public static void start(String connectionStr) {
        synchronized (zkConnectionStartStopLock) {
            if (connected.get()) {
                LOG.info("zkConnection已经启动，不再重复启动");
                return;
            }
            try {
                RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
                client = CuratorFrameworkFactory.newClient(connectionStr, retryPolicy);
                client.start();
                LOG.info("阻塞直到与zookeeper连接建立完毕！");
                client.blockUntilConnected();
            } catch (Throwable e) {
                LOG.error(e);
            } finally {
                connected.set(true);
            }
        }
    }
public static void start ( String connectionStr ) { synchronized ( zkConnectionStartStopLock ) { if ( connected . get ( ) ) { LOG . info ( "zkConnection已经启动，不再重复启动" ) ; return ; } try { RetryPolicy retryPolicy = new ExponentialBackoffRetry ( 1000 , 3 ) ; client = CuratorFrameworkFactory . newClient ( connectionStr , retryPolicy ) ; client . start ( ) ; LOG . info ( "阻塞直到与zookeeper连接建立完毕！" ) ; client . blockUntilConnected ( ) ; } catch ( Throwable e ) { LOG . error ( e ) ; } finally { connected . set ( true ) ; } } }
仅供内部测试使用