如何在ZooKeeper中实现互斥锁或对象监视器?

时间:2011-06-27 08:28:17

标签: concurrency mutex apache-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收据中找到这样的例子。

1 个答案:

答案 0 :(得分:1)

您可以在github找到分布式锁实现的示例。 您还可以查看具有curator实现的common zk reciepts zookeeper客户端。