ZkClient 事件监听器的疑问
public static void main(String[] args) throws Exception {
ZkClient zkClient = new ZkClient("127.0.0.1:2181", 5000);
zkClient.createEphemeral("/zkclient");
zkClient.subscribeDataChanges("/zkclient", new IZkDataListener() {
@Override
public void handleDataDeleted(String dataPath) throws Exception {
System.out.println(String.format("The node '%s' is deleted.", dataPath));
}
@Override
public void handleDataChange(String dataPath, Object data) throws Exception {
System.out.println(String.format("The node '%s' is changed, now its data is '%s'.", dataPath, data));
}
});
zkClient.writeData("/zkclient", "hello world");
Thread.sleep(1000);
zkClient.delete("/zkclient");
Thread.sleep(1000);
zkClient.close();
}
这段代码输出的内容是:
The node '/zkclient' is changed, now its data is 'hello world'.
The node '/zkclient' is deleted.
public static void main(String[] args) throws Exception {
ZkClient zkClient = new ZkClient("127.0.0.1:2181", 5000);
zkClient.createEphemeral("/zkclient");
zkClient.subscribeDataChanges("/zkclient", new IZkDataListener() {
@Override
public void handleDataDeleted(String dataPath) throws Exception {
System.out.println(String.format("The node '%s' is deleted.", dataPath));
}
@Override
public void handleDataChange(String dataPath, Object data) throws Exception {
System.out.println(String.format("The node '%s' is changed, now its data is '%s'.", dataPath, data));
}
});
zkClient.writeData("/zkclient", "hello world");
zkClient.delete("/zkclient");
Thread.sleep(1000);
zkClient.close();
}
这段代码的输出内容却是:
The node '/zkclient' is deleted.
The node '/zkclient' is deleted.
为什么会接收到两次删除节点事件?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论