Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

web端保存数据到zookeeper有问题,一直卡在那里 #60

Open
yanhuahayi opened this issue Mar 18, 2021 · 0 comments
Open

web端保存数据到zookeeper有问题,一直卡在那里 #60

yanhuahayi opened this issue Mar 18, 2021 · 0 comments

Comments

@yanhuahayi
Copy link

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);
    }
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant