public void waitToInitZooKeeper ( long maxWaitMillis ) throws Exception { long finished = System . currentTimeMillis ( ) + maxWaitMillis ; while ( System . currentTimeMillis ( ) < finished ) { if ( this . zooKeeper != null ) { return ; } try { Thread . sleep ( 1 ) ; } catch ( InterruptedException e ) { throw new Exception ( e ) ; } } throw new Exception ( ) ; }
Wait to init ZooKeeper object only sleep when it s null .