web端保存数据到zookeeper有问题,一直卡在那里
yanhuahayi opened this issue · 0 comments
yanhuahayi commented
public class ZooKeeperConnection {
private Logger logger = LoggerFactory.getLogger(this.getClass().getName());
private ZooKeeper zooKeeper;
private int sessionTimeout = 50000;
private final CountDownLatch connectedSignal = new CountDownLatch(1);
**public ZooKeeper connect(String host) throws IOException, InterruptedException {
**zooKeeper = new ZooKeeper(host, sessionTimeout, new Watcher() {
@Override
public void process(WatchedEvent watchedEvent) {
if(watchedEvent.getState() == Event.KeeperState.SyncConnected) {
connectedSignal.countDown();
}
}
});
connectedSignal.await();
return zooKeeper;**
}**
public void close() {
try {
zooKeeper.close();
} catch (InterruptedException e) {
logger.error("zookeeper connection close fail!", e);
}
}
}