zookeeper-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From 沈冠璞 <shengua...@360.cn>
Subject Re: getData return result between Watcher process?
Date Tue, 21 Oct 2014 11:34:22 GMT
thanks very much for your explain.
what I still puzzled is
public KeeperState getState() {
        return keeperState;
    }

    public EventType getType() {
        return eventType;
    }

    public String getPath() {
        return path;
    }

the three method should be return quickly  ,but  the thread showed interrupt ,the main thread
print   123 , I think it is wired.
沈冠璞
奇虎360  PC网游事业部
Tony Horton语录:Talk is cheap. Show me the abs.
手机:138-1143-7730
邮件:✉shenguanpu@360.cn<mailto:shenguanpu@360.cn>
地址:北京朝阳区酒仙桥路6号院(电子城•国际电子总部)2号楼A座
6楼A3   100015


[cid:image001.jpg@01CF4D0A.70BAB650]

在 2014年10月21日,上午11:01,Jürgen Wagner (DVT) <juergen.wagner@devoteam.com<mailto:juergen.wagner@devoteam.com>>
写道:

Hello,
  Zookeeper works asynchronously in several threads. Therefore the sequence of execution in
different threads is not generally predictable. It could therefore happen that when the connection
status change is detected, the Watcher is executed, but only the first "hello zookeeper" gets
echoed, then the main thread gets some cycles again and prints "123", after which the second
print statement "hello event!..." is executed. If you don't want this to happen, use a CountDownLatch
to make the main thread wait until the Zookeeper connection is established and propertly recognized
in your program. The main thread creates the CountDownLatch(1), opens the Zk connection and
waits latch.await(). The Watcher does its job and then counts the latch down by one, causing
the main thread to leave the await and continue doing its job.

Best regards,
--Jürgen

On 21.10.2014 04:40, 沈冠璞 wrote:

thanks for your reply.
but i means  the order should be :
hello zookeeper
hello event! type=None, stat=SyncConnected, path=null
123

but the real result order is :
hello zookeeper
123
hello event! type=None, stat=SyncConnected, path=null



Best Regards!
Guanpu Shen

在 2014年10月21日,上午9:07,Biju N <bijuatapache@gmail.com<mailto:bijuatapache@gmail.com><mailto:bijuatapache@gmail.com><mailto:bijuatapache@gmail.com>>
写道:

The "System.out.println(new String(zk.getData(znode,false,null)));" is
causing 123 to be displayed.

On Fri, Oct 17, 2014 at 12:15 AM, 沈冠璞 <shenguanpu@360.cn<mailto:shenguanpu@360.cn><mailto:shenguanpu@360.cn><mailto:shenguanpu@360.cn>>
wrote:

hi, I am a newbie of the zookeeper.I have a question on get data order.
here is my program:

public class ZkReader {
   public static void main(String[] args) throws IOException,
InterruptedException, KeeperException {
       String hostPort = "10.16.73.22,10.16.73.12,10.16.73.13";
       String znode = "/test";
       ZooKeeper zk = new ZooKeeper(hostPort, 3000, new MyWatcher());
       System.out.println(new String(zk.getData(znode,false,null)));
   }
}

class MyWatcher  implements Watcher {

   @Override
   public void process(WatchedEvent event) {
       System.out.println("hello zookeeper");
       System.out.println(String.format("hello event! type=%s, stat=%s,
path=%s",event.getType(),event.getState(),event.getPath()));
   }
}

the result:
hello zookeeper
123
hello event! type=None, stat=SyncConnected, path=null

I don’t know why  the data of node /test: 123 , shows between  "hello
zookeeper" and "hello event!”
Could somebody explain for me? Thanks a lot.

Best Regards!
Guanpu Shen





--

Mit freundlichen Grüßen/Kind regards/Cordialement vôtre/Atentamente/С уважением
i.A. Jürgen Wagner
Head of Competence Center "Intelligence"
& Senior Cloud Consultant

Devoteam GmbH, Industriestr. 3, 70565 Stuttgart, Germany
Phone: +49 6151 868-8725, Fax: +49 711 13353-53, Mobile: +49 171 864 1543
E-Mail: juergen.wagner@devoteam.com<mailto:juergen.wagner@devoteam.com>, URL: www.devoteam.de<http://www.devoteam.de/>

________________________________
Managing Board: Jürgen Hatzipantelis (CEO)
Address of Record: 64331 Weiterstadt, Germany; Commercial Register: Amtsgericht Darmstadt
HRB 6450; Tax Number: DE 172 993 071


Mime
  • Unnamed multipart/related (inline, None, 0 bytes)
View raw message