如何在ZooKeeper中实现互斥锁或对象监视器?
我想使用 ZooKeeper 实现简单的类,
public class ResourceMonitor implements Watcher {
String name = "/zk_test3";
ZooKeeper zk;
public ResourceMonitor() throws IOException {
zk = new ZooKeeper("localhost:8000", 3000, this);
}
public void waitAndGet() {
}
public void release() {
//remove children
}
public void process(WatchedEvent event) {
System.out.println("ResourceMonitor:" + event.toString());
}
}
我是 ZooKeeper 的新手,在 ZooKeeper 收据中没有找到这样的示例。
I want to implement simple class using ZooKeeper
public class ResourceMonitor implements Watcher {
String name = "/zk_test3";
ZooKeeper zk;
public ResourceMonitor() throws IOException {
zk = new ZooKeeper("localhost:8000", 3000, this);
}
public void waitAndGet() {
}
public void release() {
//remove children
}
public void process(WatchedEvent event) {
System.out.println("ResourceMonitor:" + event.toString());
}
}
I'm new to ZooKeeper and didn't find such example in ZooKeeper receipts.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在 github。
您还可以查看 curator Zookeeper 客户端,它具有 常见的 zk 收据。
You can find example of distributed lock implementation at github.
Also you can take a look at curator zookeeper client which has implementations of common zk reciepts.