When you allocate a ZooKeeper instance, you must wait for the SyncConnected event. If you try to create a node before you receive this event you’ll get a connection error. It’s because of this (and many other reasons) that I wrote Curator. If you’re using ZooKeeper in the JVM I encourage you to use Apache Curator: http://curator.apache.org

From: Lahiru Gunathilake [EMAIL PROTECTED]
Date: June 20, 2014 at 8:42:54 AM
Subject:  Time issue in zookeeper client  

Hi All,  

I am using zookeeper to register cluster nodes. In my system the default  
scenario we have multiple thrift services(different services and default  
mode 1 thrift service for each in a single jvm ) registering them selves  
(default try out mode), In that case one service makes parent nodes others  
just checks the existence of parent and in-case it doesn't exist they will  
make the parent nodes and register with the ephemaral node.  

When I start my jvm I see the last thrift service always consistently fail  
and when I add a thread sleep it worked. When I start the last service in a  
separate jvm it works. Is there anything I am doing wrong.  

Code looks as below for failing service. Other services does the same.  

zk = new ZooKeeper(zkhostPort, 6000, this); // no watcher is required,  
this will only use to store some data  
String gfacServer =  
Thread.sleep(1000); // this fixed my issue but not sure why  
its failing  
Stat zkStat = zk.exists(gfacServer, false);  
if (zkStat == null) {  
zk.create(gfacServer, new byte[0],  
String instantNode = gfacServer + File.separator +  
String.valueOf(new Random().nextInt(Integer.MAX_VALUE));  
zkStat = zk.exists(instantNode, false);  
if (zkStat == null) {  
CreateMode.EPHEMERAL); // other component  
will watch these childeren creation deletion to monitor the status of the  

Am I doing anything wrong ?  

System Analyst Programmer  
PTI Lab  
Indiana University  

NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB