{"id":95031,"date":"2026-08-16T01:01:11","date_gmt":"2026-08-15T17:01:11","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/95031.html"},"modified":"2026-08-16T01:01:11","modified_gmt":"2026-08-15T17:01:11","slug":"zookeeper-java-api-%e5%ae%9e%e7%8e%b0%e8%8a%82%e7%82%b9%e7%9a%84%e5%88%9b%e5%bb%ba%e4%b8%8e%e5%88%a0%e9%99%a4%e5%bc%80%e5%8f%91-2","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/95031.html","title":{"rendered":"Zookeeper - Java API \u5b9e\u73b0\u8282\u70b9\u7684\u521b\u5efa\u4e0e\u5220\u9664\u5f00\u53d1"},"content":{"rendered":"<h3>1. \u5f15\u8a00<\/h3>\n<p>Apache ZooKeeper \u662f\u4e00\u4e2a\u5206\u5e03\u5f0f\u7684\u3001\u5f00\u653e\u6e90\u7801\u7684\u5206\u5e03\u5f0f\u5e94\u7528\u7a0b\u5e8f\u534f\u8c03\u670d\u52a1&#xff0c;\u662f Hadoop \u548c HBase \u7684\u91cd\u8981\u7ec4\u4ef6\u3002\u5b83\u4e3b\u8981\u7528\u4e8e\u89e3\u51b3\u5206\u5e03\u5f0f\u5e94\u7528\u4e2d\u7ecf\u5e38\u9047\u5230\u7684\u4e00\u4e9b\u6570\u636e\u7ba1\u7406\u95ee\u9898&#xff0c;\u5982\u7edf\u4e00\u547d\u540d\u670d\u52a1\u3001\u72b6\u6001\u540c\u6b65\u670d\u52a1\u3001\u96c6\u7fa4\u7ba1\u7406\u3001\u5206\u5e03\u5f0f\u5e94\u7528\u914d\u7f6e\u9879\u7684\u7ba1\u7406\u7b49\u3002<\/p>\n<p>ZooKeeper \u7684\u6570\u636e\u6a21\u578b\u91c7\u7528\u7c7b\u4f3c\u6587\u4ef6\u7cfb\u7edf\u7684\u6811\u72b6\u7ed3\u6784&#xff0c;\u6bcf\u4e2a\u8282\u70b9\u79f0\u4e3a\u4e00\u4e2a ZNode\u3002ZNode \u662f ZooKeeper \u4e2d\u6570\u636e\u5b58\u50a8\u7684\u57fa\u672c\u5355\u5143&#xff0c;\u53ef\u4ee5\u5b58\u50a8\u6570\u636e&#xff0c;\u4e5f\u53ef\u4ee5\u6709\u5b50\u8282\u70b9\u3002\u5bf9 ZNode \u7684\u521b\u5efa\u3001\u5220\u9664\u3001\u8bfb\u53d6\u548c\u66f4\u65b0\u64cd\u4f5c\u662f ZooKeeper \u5ba2\u6237\u7aef\u6700\u6838\u5fc3\u7684 API\u3002<\/p>\n<p>\u672c\u6587\u5c06\u91cd\u70b9\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528 ZooKeeper \u7684 Java API \u8fdb\u884c\u8282\u70b9\u7684\u521b\u5efa\u4e0e\u5220\u9664\u64cd\u4f5c&#xff0c;\u8fd9\u662f\u8fdb\u884c ZooKeeper \u5e94\u7528\u5f00\u53d1\u7684\u57fa\u7840\u3002<\/p>\n<h3>2. \u73af\u5883\u51c6\u5907<\/h3>\n<h4>2.1 \u4f9d\u8d56\u5f15\u5165<\/h4>\n<p>\u9996\u5148&#xff0c;\u9700\u8981\u5728\u9879\u76ee\u4e2d\u5f15\u5165 ZooKeeper \u7684 Java \u5ba2\u6237\u7aef\u4f9d\u8d56\u3002\u4ee5 Maven \u9879\u76ee\u4e3a\u4f8b&#xff0c;\u5728 pom.xml \u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4f9d\u8d56&#xff1a;<\/p>\n<p>&lt;dependency&gt;<br \/>\n    &lt;groupId&gt;org.apache.zookeeper&lt;\/groupId&gt;<br \/>\n    &lt;artifactId&gt;zookeeper&lt;\/artifactId&gt;<br \/>\n    &lt;version&gt;3.8.0&lt;\/version&gt;<br \/>\n&lt;\/dependency&gt;<\/p>\n<h4>http:\/\/my.tv.sohu.com\/us\/445385256\/737670875.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/445385256\/737670954.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/445385256\/737670749.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/445385256\/737670911.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/445385256\/737670832.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/445385256\/737670382.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/445385256\/737670285.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/445385256\/737670360.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/445385256\/737670262.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/445385256\/737669895.shtml<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1Mzg1MjU2LzczNzY3MDg3NS5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1Mzg1MjU2LzczNzY3MDk1NC5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1Mzg1MjU2LzczNzY3MDc0OS5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1Mzg1MjU2LzczNzY3MDkxMS5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1Mzg1MjU2LzczNzY3MDgzMi5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1Mzg1MjU2LzczNzY3MDM4Mi5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1Mzg1MjU2LzczNzY3MDI4NS5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1Mzg1MjU2LzczNzY3MDM2MC5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1Mzg1MjU2LzczNzY3MDI2Mi5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1Mzg1MjU2LzczNzY2OTg5NS5zaHRtbA&#061;&#061;.html<br \/>\n&#xff0c;&#xff0c;&#xff0c;&#xff0c;<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/370099978\/737671903.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/370099978\/737671733.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/370099978\/737671823.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/370099978\/737671726.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/370099978\/737671718.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/370099978\/737671805.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/370099978\/737671400.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/370099978\/737671631.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/370099978\/737671702.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/370099978\/737671383.shtml<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvMzcwMDk5OTc4LzczNzY3MTkwMy5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvMzcwMDk5OTc4LzczNzY3MTczMy5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvMzcwMDk5OTc4LzczNzY3MTgyMy5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvMzcwMDk5OTc4LzczNzY3MTcyNi5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvMzcwMDk5OTc4LzczNzY3MTcxOC5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvMzcwMDk5OTc4LzczNzY3MTgwNS5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvMzcwMDk5OTc4LzczNzY3MTQwMC5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvMzcwMDk5OTc4LzczNzY3MTYzMS5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvMzcwMDk5OTc4LzczNzY3MTcwMi5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvMzcwMDk5OTc4LzczNzY3MTM4My5zaHRtbA&#061;&#061;.html<br \/>\n&#xff0c;&#xff0c;&#xff0c;&#xff0c;<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/445135000\/737672173.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/445135000\/737672342.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/445135000\/737672336.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/445135000\/737672333.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/445135000\/737672152.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/445135000\/737672239.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/445135000\/737672308.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/445135000\/737672132.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/445135000\/737672069.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/445135000\/737672221.shtml<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1MTM1MDAwLzczNzY3MjE3My5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1MTM1MDAwLzczNzY3MjM0Mi5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1MTM1MDAwLzczNzY3MjMzNi5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1MTM1MDAwLzczNzY3MjMzMy5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1MTM1MDAwLzczNzY3MjE1Mi5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1MTM1MDAwLzczNzY3MjIzOS5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1MTM1MDAwLzczNzY3MjMwOC5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1MTM1MDAwLzczNzY3MjEzMi5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1MTM1MDAwLzczNzY3MjA2OS5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1MTM1MDAwLzczNzY3MjIyMS5zaHRtbA&#061;&#061;.html<\/h4>\n<h4>2.2 \u542f\u52a8 ZooKeeper \u670d\u52a1<\/h4>\n<p>\u5728\u5f00\u53d1\u4e4b\u524d&#xff0c;\u9700\u8981\u786e\u4fdd\u6709\u4e00\u4e2a\u53ef\u7528\u7684 ZooKeeper \u670d\u52a1\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u4e4b\u4e00\u542f\u52a8&#xff1a;<\/p>\n<ul>\n<li>\u5355\u673a\u6a21\u5f0f&#xff1a;\u4e0b\u8f7d ZooKeeper \u53d1\u884c\u7248&#xff0c;\u89e3\u538b\u540e\u4fee\u6539 conf\/zoo.cfg \u914d\u7f6e\u6587\u4ef6&#xff0c;\u7136\u540e\u8fd0\u884c bin\/zkServer.sh start&#xff08;Linux\/Mac&#xff09;\u6216 bin\/zkServer.cmd&#xff08;Windows&#xff09;\u3002<\/li>\n<li>Docker \u65b9\u5f0f&#xff1a;\u8fd0\u884c docker run &#8211;name zookeeper -p 2181:2181 -d zookeeper:3.8\u3002<\/li>\n<\/ul>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b&#xff0c;ZooKeeper \u670d\u52a1\u4f1a\u5728 localhost:2181 \u7aef\u53e3\u76d1\u542c\u3002<\/p>\n<h3>3. \u521b\u5efa ZooKeeper \u5ba2\u6237\u7aef\u8fde\u63a5<\/h3>\n<p>\u5728\u8fdb\u884c\u4efb\u4f55\u8282\u70b9\u64cd\u4f5c\u4e4b\u524d&#xff0c;\u9996\u5148\u9700\u8981\u5efa\u7acb\u4e0e ZooKeeper \u670d\u52a1\u5668\u7684\u8fde\u63a5\u3002ZooKeeper \u5ba2\u6237\u7aef\u901a\u8fc7 ZooKeeper \u7c7b\u6765\u521b\u5efa\u548c\u7ba1\u7406\u8fde\u63a5\u3002<\/p>\n<p>import org.apache.zookeeper.WatchedEvent;<br \/>\nimport org.apache.zookeeper.Watcher;<br \/>\nimport org.apache.zookeeper.ZooKeeper;<br \/>\nimport java.io.IOException;<br \/>\nimport java.util.concurrent.CountDownLatch;<\/p>\n<p>public class ZkClientDemo {<br \/>\n    private static final String CONNECT_STRING &#061; &#034;localhost:2181&#034;;<br \/>\n    private static final int SESSION_TIMEOUT &#061; 5000; \/\/ \u4f1a\u8bdd\u8d85\u65f6\u65f6\u95f4&#xff0c;\u5355\u4f4d\u6beb\u79d2<\/p>\n<p>    public static ZooKeeper getConnection() throws IOException, InterruptedException {<br \/>\n        CountDownLatch connectedLatch &#061; new CountDownLatch(1);<br \/>\n        \/\/ \u521b\u5efa ZooKeeper \u5b9e\u4f8b&#xff0c;\u5f02\u6b65\u8fde\u63a5<br \/>\n        ZooKeeper zk &#061; new ZooKeeper(CONNECT_STRING, SESSION_TIMEOUT, new Watcher() {<br \/>\n            &#064;Override<br \/>\n            public void process(WatchedEvent event) {<br \/>\n                if (event.getState() &#061;&#061; Event.KeeperState.SyncConnected) {<br \/>\n                    \/\/ \u8fde\u63a5\u5efa\u7acb\u6210\u529f<br \/>\n                    connectedLatch.countDown();<br \/>\n                }<br \/>\n            }<br \/>\n        });<br \/>\n        \/\/ \u7b49\u5f85\u8fde\u63a5\u5efa\u7acb\u5b8c\u6210<br \/>\n        connectedLatch.await();<br \/>\n        System.out.println(&#034;ZooKeeper \u8fde\u63a5\u5efa\u7acb\u6210\u529f&#xff01;&#034;);<br \/>\n        return zk;<br \/>\n    }<br \/>\n}<\/p>\n<p>\u5173\u952e\u53c2\u6570\u8bf4\u660e&#xff1a;<\/p>\n<ul>\n<li>connectString&#xff1a;ZooKeeper \u670d\u52a1\u5668\u5730\u5740&#xff0c;\u683c\u5f0f\u4e3a host:port&#xff0c;\u591a\u4e2a\u5730\u5740\u7528\u9017\u53f7\u5206\u9694\u3002<\/li>\n<li>sessionTimeout&#xff1a;\u4f1a\u8bdd\u8d85\u65f6\u65f6\u95f4&#xff0c;\u5355\u4f4d\u6beb\u79d2\u3002\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u5931\u53bb\u8fde\u63a5\u540e&#xff0c;\u5728\u6b64\u65f6\u95f4\u5185\u91cd\u8fde\u6210\u529f\u53ef\u6062\u590d\u4f1a\u8bdd\u3002<\/li>\n<li>watcher&#xff1a;\u9ed8\u8ba4\u7684 Watcher&#xff0c;\u7528\u4e8e\u63a5\u6536\u8fde\u63a5\u72b6\u6001\u53d8\u5316\u7b49\u4e8b\u4ef6\u901a\u77e5\u3002<\/li>\n<\/ul>\n<h3>4. \u521b\u5efa\u8282\u70b9&#xff08;Create&#xff09;<\/h3>\n<p>ZooKeeper \u63d0\u4f9b\u4e86 create \u65b9\u6cd5\u6765\u521b\u5efa\u8282\u70b9\u3002\u521b\u5efa\u8282\u70b9\u65f6\u9700\u8981\u6307\u5b9a\u8def\u5f84\u3001\u6570\u636e\u3001ACL&#xff08;\u8bbf\u95ee\u63a7\u5236\u5217\u8868&#xff09;\u548c\u8282\u70b9\u7c7b\u578b\u3002<\/p>\n<h4>4.1 \u8282\u70b9\u7c7b\u578b<\/h4>\n<p>ZooKeeper \u652f\u6301\u4ee5\u4e0b\u51e0\u79cd\u8282\u70b9\u7c7b\u578b&#xff1a;<\/p>\n<ul>\n<li>\u6301\u4e45\u8282\u70b9&#xff08;PERSISTENT&#xff09;&#xff1a;\u521b\u5efa\u540e\u4e00\u76f4\u5b58\u5728&#xff0c;\u76f4\u5230\u88ab\u663e\u5f0f\u5220\u9664\u3002<\/li>\n<li>\u6301\u4e45\u987a\u5e8f\u8282\u70b9&#xff08;PERSISTENT_SEQUENTIAL&#xff09;&#xff1a;\u6301\u4e45\u8282\u70b9&#xff0c;\u4f46\u8282\u70b9\u540d\u540e\u4f1a\u9644\u52a0\u4e00\u4e2a\u5355\u8c03\u9012\u589e\u7684\u5e8f\u53f7\u3002<\/li>\n<li>\u4e34\u65f6\u8282\u70b9&#xff08;EPHEMERAL&#xff09;&#xff1a;\u4e0e\u5ba2\u6237\u7aef\u4f1a\u8bdd\u7ed1\u5b9a&#xff0c;\u4f1a\u8bdd\u7ed3\u675f&#xff08;\u8fde\u63a5\u65ad\u5f00&#xff09;\u540e\u8282\u70b9\u81ea\u52a8\u5220\u9664\u3002<\/li>\n<li>\u4e34\u65f6\u987a\u5e8f\u8282\u70b9&#xff08;EPHEMERAL_SEQUENTIAL&#xff09;&#xff1a;\u4e34\u65f6\u8282\u70b9&#xff0c;\u8282\u70b9\u540d\u540e\u9644\u52a0\u5e8f\u53f7\u3002<\/li>\n<\/ul>\n<h4>4.2 \u521b\u5efa\u6301\u4e45\u8282\u70b9\u793a\u4f8b<\/h4>\n<p>import org.apache.zookeeper.CreateMode;<br \/>\nimport org.apache.zookeeper.ZooDefs;<br \/>\nimport org.apache.zookeeper.data.ACL;<br \/>\nimport java.util.List;<\/p>\n<p>public class ZkCreateDemo {<br \/>\n    public static void createPersistentNode(ZooKeeper zk, String path, String data) throws Exception {<br \/>\n        \/\/ \u9ed8\u8ba4\u4f7f\u7528 OPEN_ACL_UNSAFE&#xff08;\u6240\u6709\u4eba\u62e5\u6709\u6240\u6709\u6743\u9650&#xff09;<br \/>\n        List&lt;ACL&gt; acl &#061; ZooDefs.Ids.OPEN_ACL_UNSAFE;<br \/>\n        \/\/ \u521b\u5efa\u6301\u4e45\u8282\u70b9<br \/>\n        String createdPath &#061; zk.create(path,<br \/>\n                                      data.getBytes(),<br \/>\n                                      acl,<br \/>\n                                      CreateMode.PERSISTENT);<br \/>\n        System.out.println(&#034;\u6301\u4e45\u8282\u70b9\u521b\u5efa\u6210\u529f&#xff0c;\u8def\u5f84: &#034; &#043; createdPath);<br \/>\n    }<\/p>\n<p>    public static void main(String[] args) throws Exception {<br \/>\n        ZooKeeper zk &#061; ZkClientDemo.getConnection();<br \/>\n        \/\/ \u521b\u5efa \/demo \u8282\u70b9&#xff0c;\u6570\u636e\u4e3a &#034;hello zookeeper&#034;<br \/>\n        createPersistentNode(zk, &#034;\/demo&#034;, &#034;hello zookeeper&#034;);<br \/>\n        zk.close();<br \/>\n    }<br \/>\n}<\/p>\n<h4>4.3 \u521b\u5efa\u4e34\u65f6\u8282\u70b9\u793a\u4f8b<\/h4>\n<p>public class ZkCreateEphemeralDemo {<br \/>\n    public static void createEphemeralNode(ZooKeeper zk, String path, String data) throws Exception {<br \/>\n        String createdPath &#061; zk.create(path,<br \/>\n                                      data.getBytes(),<br \/>\n                                      ZooDefs.Ids.OPEN_ACL_UNSAFE,<br \/>\n                                      CreateMode.EPHEMERAL);<br \/>\n        System.out.println(&#034;\u4e34\u65f6\u8282\u70b9\u521b\u5efa\u6210\u529f&#xff0c;\u8def\u5f84: &#034; &#043; createdPath);<br \/>\n        \/\/ \u4e34\u65f6\u8282\u70b9\u4f1a\u5728\u4f1a\u8bdd\u7ed3\u675f\u540e\u81ea\u52a8\u5220\u9664<br \/>\n    }<\/p>\n<p>    public static void main(String[] args) throws Exception {<br \/>\n        ZooKeeper zk &#061; ZkClientDemo.getConnection();<br \/>\n        createEphemeralNode(zk, &#034;\/tempNode&#034;, &#034;\u4e34\u65f6\u6570\u636e&#034;);<br \/>\n        \/\/ \u4fdd\u6301\u8fde\u63a5&#xff0c;\u89c2\u5bdf\u8282\u70b9\u5b58\u5728<br \/>\n        Thread.sleep(10000);<br \/>\n        zk.close(); \/\/ \u5173\u95ed\u8fde\u63a5\u540e&#xff0c;\u4e34\u65f6\u8282\u70b9\u4f1a\u88ab\u81ea\u52a8\u5220\u9664<br \/>\n    }<br \/>\n}<\/p>\n<h4>4.4 \u521b\u5efa\u987a\u5e8f\u8282\u70b9\u793a\u4f8b<\/h4>\n<p>public class ZkCreateSequentialDemo {<br \/>\n    public static void createSequentialNode(ZooKeeper zk, String path, String data) throws Exception {<br \/>\n        \/\/ \u521b\u5efa\u6301\u4e45\u987a\u5e8f\u8282\u70b9<br \/>\n        String createdPath &#061; zk.create(path,<br \/>\n                                      data.getBytes(),<br \/>\n                                      ZooDefs.Ids.OPEN_ACL_UNSAFE,<br \/>\n                                      CreateMode.PERSISTENT_SEQUENTIAL);<br \/>\n        System.out.println(&#034;\u987a\u5e8f\u8282\u70b9\u521b\u5efa\u6210\u529f&#xff0c;\u5b9e\u9645\u8def\u5f84: &#034; &#043; createdPath);<br \/>\n        \/\/ \u5982\u679c path \u662f &#034;\/seq-&#034;&#xff0c;\u5b9e\u9645\u521b\u5efa\u7684\u8def\u5f84\u53ef\u80fd\u662f &#034;\/seq-0000000001&#034;<br \/>\n    }<\/p>\n<p>    public static void main(String[] args) throws Exception {<br \/>\n        ZooKeeper zk &#061; ZkClientDemo.getConnection();<br \/>\n        \/\/ \u8fde\u7eed\u521b\u5efa\u4e09\u4e2a\u987a\u5e8f\u8282\u70b9<br \/>\n        createSequentialNode(zk, &#034;\/seq-&#034;, &#034;data1&#034;);<br \/>\n        createSequentialNode(zk, &#034;\/seq-&#034;, &#034;data2&#034;);<br \/>\n        createSequentialNode(zk, &#034;\/seq-&#034;, &#034;data3&#034;);<br \/>\n        zk.close();<br \/>\n    }<br \/>\n}<\/p>\n<h3>5. \u5220\u9664\u8282\u70b9&#xff08;Delete&#xff09;<\/h3>\n<p>ZooKeeper \u63d0\u4f9b\u4e86 delete \u65b9\u6cd5\u6765\u5220\u9664\u8282\u70b9\u3002\u5220\u9664\u8282\u70b9\u65f6\u9700\u8981\u6ce8\u610f&#xff1a;<\/p>\n<li>\u53ea\u80fd\u5220\u9664\u6ca1\u6709\u5b50\u8282\u70b9\u7684\u8282\u70b9\u3002<\/li>\n<li>\u53ef\u4ee5\u6307\u5b9a\u7248\u672c\u53f7\u8fdb\u884c\u6761\u4ef6\u5220\u9664&#xff08;CAS \u64cd\u4f5c&#xff09;\u3002<\/li>\n<h4>5.1 \u7b80\u5355\u5220\u9664\u8282\u70b9<\/h4>\n<p>import org.apache.zookeeper.KeeperException;<\/p>\n<p>public class ZkDeleteDemo {<br \/>\n    public static void deleteNode(ZooKeeper zk, String path) throws Exception {<br \/>\n        try {<br \/>\n            \/\/ version &#061; -1 \u8868\u793a\u5ffd\u7565\u7248\u672c\u53f7&#xff0c;\u76f4\u63a5\u5220\u9664<br \/>\n            zk.delete(path, -1);<br \/>\n            System.out.println(&#034;\u8282\u70b9\u5220\u9664\u6210\u529f: &#034; &#043; path);<br \/>\n        } catch (KeeperException.NoNodeException e) {<br \/>\n            System.out.println(&#034;\u8282\u70b9\u4e0d\u5b58\u5728: &#034; &#043; path);<br \/>\n        } catch (KeeperException.NotEmptyException e) {<br \/>\n            System.out.println(&#034;\u8282\u70b9 &#034; &#043; path &#043; &#034; \u4e0b\u5b58\u5728\u5b50\u8282\u70b9&#xff0c;\u65e0\u6cd5\u5220\u9664&#034;);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    public static void main(String[] args) throws Exception {<br \/>\n        ZooKeeper zk &#061; ZkClientDemo.getConnection();<\/p>\n<p>        \/\/ \u5148\u521b\u5efa\u4e00\u4e2a\u6d4b\u8bd5\u8282\u70b9<br \/>\n        zk.create(&#034;\/testDelete&#034;, &#034;to be deleted&#034;.getBytes(),<br \/>\n                 ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);<\/p>\n<p>        \/\/ \u5220\u9664\u8be5\u8282\u70b9<br \/>\n        deleteNode(zk, &#034;\/testDelete&#034;);<\/p>\n<p>        zk.close();<br \/>\n    }<br \/>\n}<\/p>\n<h4>5.2 \u5e26\u7248\u672c\u53f7\u7684\u5220\u9664&#xff08;CAS&#xff09;<\/h4>\n<p>ZooKeeper \u4e2d\u6bcf\u4e2a\u8282\u70b9\u90fd\u6709\u4e00\u4e2a\u6570\u636e\u7248\u672c\u53f7&#xff08;version&#xff09;&#xff0c;\u6bcf\u6b21\u6570\u636e\u66f4\u65b0\u7248\u672c\u53f7\u90fd\u4f1a\u9012\u589e\u3002\u5220\u9664\u65f6\u53ef\u4ee5\u6307\u5b9a\u7248\u672c\u53f7&#xff0c;\u53ea\u6709\u5f53\u524d\u7248\u672c\u53f7\u5339\u914d\u65f6\u624d\u4f1a\u6267\u884c\u5220\u9664&#xff0c;\u8fd9\u5b9e\u73b0\u4e86\u4e50\u89c2\u9501\u673a\u5236\u3002<\/p>\n<p>public class ZkDeleteWithVersionDemo {<br \/>\n    public static void deleteNodeWithVersion(ZooKeeper zk, String path, int expectedVersion) throws Exception {<br \/>\n        try {<br \/>\n            zk.delete(path, expectedVersion);<br \/>\n            System.out.println(&#034;\u8282\u70b9\u5220\u9664\u6210\u529f: &#034; &#043; path &#043; &#034; (\u7248\u672c: &#034; &#043; expectedVersion &#043; &#034;)&#034;);<br \/>\n        } catch (KeeperException.BadVersionException e) {<br \/>\n            System.out.println(&#034;\u7248\u672c\u4e0d\u5339\u914d&#xff0c;\u5220\u9664\u5931\u8d25\u3002\u5f53\u524d\u7248\u672c\u53ef\u80fd\u5df2\u88ab\u5176\u4ed6\u5ba2\u6237\u7aef\u4fee\u6539\u3002&#034;);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    public static void main(String[] args) throws Exception {<br \/>\n        ZooKeeper zk &#061; ZkClientDemo.getConnection();<\/p>\n<p>        \/\/ \u521b\u5efa\u8282\u70b9\u5e76\u83b7\u53d6\u5176\u5f53\u524d\u72b6\u6001&#xff08;\u5305\u542b\u7248\u672c\u53f7&#xff09;<br \/>\n        zk.create(&#034;\/casNode&#034;, &#034;initial&#034;.getBytes(),<br \/>\n                 ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);<\/p>\n<p>        \/\/ \u83b7\u53d6\u8282\u70b9\u72b6\u6001&#xff0c;\u5f97\u5230\u5f53\u524d\u7248\u672c\u53f7<br \/>\n        org.apache.zookeeper.data.Stat stat &#061; zk.exists(&#034;\/casNode&#034;, false);<br \/>\n        int currentVersion &#061; stat.getVersion();<br \/>\n        System.out.println(&#034;\u5f53\u524d\u8282\u70b9\u7248\u672c: &#034; &#043; currentVersion);<\/p>\n<p>        \/\/ \u4f7f\u7528\u6b63\u786e\u7248\u672c\u53f7\u5220\u9664&#xff08;\u5e94\u8be5\u6210\u529f&#xff09;<br \/>\n        deleteNodeWithVersion(zk, &#034;\/casNode&#034;, currentVersion);<\/p>\n<p>        \/\/ \u5c1d\u8bd5\u4f7f\u7528\u9519\u8bef\u7248\u672c\u53f7\u5220\u9664&#xff08;\u5e94\u8be5\u5931\u8d25&#xff09;<br \/>\n        \/\/ deleteNodeWithVersion(zk, &#034;\/casNode&#034;, currentVersion); \/\/ \u8282\u70b9\u5df2\u4e0d\u5b58\u5728<\/p>\n<p>        zk.close();<br \/>\n    }<br \/>\n}<\/p>\n<h4>5.3 \u9012\u5f52\u5220\u9664\u975e\u7a7a\u8282\u70b9<\/h4>\n<p>ZooKeeper \u539f\u751f\u7684 delete \u65b9\u6cd5\u4e0d\u80fd\u5220\u9664\u542b\u6709\u5b50\u8282\u70b9\u7684\u8282\u70b9\u3002\u5982\u679c\u9700\u8981\u5220\u9664\u6574\u4e2a\u5b50\u6811&#xff0c;\u9700\u8981\u5148\u9012\u5f52\u5220\u9664\u6240\u6709\u5b50\u8282\u70b9\u3002<\/p>\n<p>import java.util.List;<\/p>\n<p>public class ZkDeleteRecursiveDemo {<br \/>\n    public static void deleteRecursive(ZooKeeper zk, String path) throws Exception {<br \/>\n        \/\/ \u83b7\u53d6\u5b50\u8282\u70b9\u5217\u8868<br \/>\n        List&lt;String&gt; children &#061; zk.getChildren(path, false);<br \/>\n        for (String child : children) {<br \/>\n            String childPath &#061; path.equals(&#034;\/&#034;) ? &#034;\/&#034; &#043; child : path &#043; &#034;\/&#034; &#043; child;<br \/>\n            deleteRecursive(zk, childPath); \/\/ \u9012\u5f52\u5220\u9664\u5b50\u8282\u70b9<br \/>\n        }<br \/>\n        \/\/ \u5220\u9664\u5f53\u524d\u8282\u70b9<br \/>\n        try {<br \/>\n            zk.delete(path, -1);<br \/>\n            System.out.println(&#034;\u5220\u9664\u8282\u70b9: &#034; &#043; path);<br \/>\n        } catch (KeeperException.NoNodeException e) {<br \/>\n            \/\/ \u8282\u70b9\u53ef\u80fd\u5df2\u88ab\u5220\u9664&#xff0c;\u5ffd\u7565<br \/>\n        }<br \/>\n    }<\/p>\n<p>    public static void main(String[] args) throws Exception {<br \/>\n        ZooKeeper zk &#061; ZkClientDemo.getConnection();<\/p>\n<p>        \/\/ \u521b\u5efa\u6d4b\u8bd5\u6811\u7ed3\u6784<br \/>\n        zk.create(&#034;\/parent&#034;, &#034;parent data&#034;.getBytes(),<br \/>\n                 ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);<br \/>\n        zk.create(&#034;\/parent\/child1&#034;, &#034;child1&#034;.getBytes(),<br \/>\n                 ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);<br \/>\n        zk.create(&#034;\/parent\/child2&#034;, &#034;child2&#034;.getBytes(),<br \/>\n                 ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);<br \/>\n        zk.create(&#034;\/parent\/child1\/grandchild&#034;, &#034;grand&#034;.getBytes(),<br \/>\n                 ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);<\/p>\n<p>        \/\/ \u9012\u5f52\u5220\u9664\u6574\u4e2a \/parent \u5b50\u6811<br \/>\n        deleteRecursive(zk, &#034;\/parent&#034;);<\/p>\n<p>        zk.close();<br \/>\n    }<br \/>\n}<\/p>\n<h3>6. \u5b8c\u6574\u793a\u4f8b&#xff1a;\u8282\u70b9\u7ba1\u7406\u5de5\u5177\u7c7b<\/h3>\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u6574\u5408\u4e86\u521b\u5efa\u548c\u5220\u9664\u529f\u80fd\u7684\u5de5\u5177\u7c7b&#xff0c;\u5305\u542b\u5f02\u5e38\u5904\u7406\u548c\u8fde\u63a5\u7ba1\u7406\u3002<\/p>\n<p>import org.apache.zookeeper.*;<br \/>\nimport org.apache.zookeeper.data.ACL;<br \/>\nimport org.apache.zookeeper.data.Stat;<br \/>\nimport java.io.IOException;<br \/>\nimport java.util.List;<br \/>\nimport java.util.concurrent.CountDownLatch;<\/p>\n<p>public class ZkNodeManager {<br \/>\n    private ZooKeeper zk;<br \/>\n    private final String connectString;<br \/>\n    private final int sessionTimeout;<\/p>\n<p>    public ZkNodeManager(String connectString, int sessionTimeout) {<br \/>\n        this.connectString &#061; connectString;<br \/>\n        this.sessionTimeout &#061; sessionTimeout;<br \/>\n    }<\/p>\n<p>    \/\/ \u5efa\u7acb\u8fde\u63a5<br \/>\n    public void connect() throws IOException, InterruptedException {<br \/>\n        CountDownLatch latch &#061; new CountDownLatch(1);<br \/>\n        this.zk &#061; new ZooKeeper(connectString, sessionTimeout, event -&gt; {<br \/>\n            if (event.getState() &#061;&#061; Watcher.Event.KeeperState.SyncConnected) {<br \/>\n                latch.countDown();<br \/>\n            }<br \/>\n        });<br \/>\n        latch.await();<br \/>\n        System.out.println(&#034;Connected to ZooKeeper: &#034; &#043; connectString);<br \/>\n    }<\/p>\n<p>    \/\/ \u5173\u95ed\u8fde\u63a5<br \/>\n    public void close() throws InterruptedException {<br \/>\n        if (zk !&#061; null) {<br \/>\n            zk.close();<br \/>\n            System.out.println(&#034;ZooKeeper connection closed.&#034;);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/\/ \u521b\u5efa\u8282\u70b9<br \/>\n    public String createNode(String path, String data, CreateMode mode) throws KeeperException, InterruptedException {<br \/>\n        return createNode(path, data.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, mode);<br \/>\n    }<\/p>\n<p>    public String createNode(String path, byte[] data, List&lt;ACL&gt; acl, CreateMode mode)<br \/>\n            throws KeeperException, InterruptedException {<br \/>\n        return zk.create(path, data, acl, mode);<br \/>\n    }<\/p>\n<p>    \/\/ \u5220\u9664\u8282\u70b9<br \/>\n    public boolean deleteNode(String path) throws KeeperException, InterruptedException {<br \/>\n        return deleteNode(path, -1);<br \/>\n    }<\/p>\n<p>    public boolean deleteNode(String path, int version) throws KeeperException, InterruptedException {<br \/>\n        try {<br \/>\n            zk.delete(path, version);<br \/>\n            return true;<br \/>\n        } catch (KeeperException.NoNodeException e) {<br \/>\n            System.out.println(&#034;Node does not exist: &#034; &#043; path);<br \/>\n            return false;<br \/>\n        } catch (KeeperException.NotEmptyException e) {<br \/>\n            System.out.println(&#034;Node has children, cannot delete: &#034; &#043; path);<br \/>\n            return false;<br \/>\n        } catch (KeeperException.BadVersionException e) {<br \/>\n            System.out.println(&#034;Version mismatch for node: &#034; &#043; path);<br \/>\n            return false;<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/\/ \u9012\u5f52\u5220\u9664\u8282\u70b9\u53ca\u5176\u5b50\u8282\u70b9<br \/>\n    public void deleteRecursive(String path) throws KeeperException, InterruptedException {<br \/>\n        List&lt;String&gt; children &#061; zk.getChildren(path, false);<br \/>\n        for (String child : children) {<br \/>\n            String childPath &#061; path.equals(&#034;\/&#034;) ? &#034;\/&#034; &#043; child : path &#043; &#034;\/&#034; &#043; child;<br \/>\n            deleteRecursive(childPath);<br \/>\n        }<br \/>\n        deleteNode(path);<br \/>\n    }<\/p>\n<p>    \/\/ \u68c0\u67e5\u8282\u70b9\u662f\u5426\u5b58\u5728<br \/>\n    public boolean exists(String path) throws KeeperException, InterruptedException {<br \/>\n        Stat stat &#061; zk.exists(path, false);<br \/>\n        return stat !&#061; null;<br \/>\n    }<\/p>\n<p>    \/\/ \u4f7f\u7528\u793a\u4f8b<br \/>\n    public static void main(String[] args) throws Exception {<br \/>\n        ZkNodeManager manager &#061; new ZkNodeManager(&#034;localhost:2181&#034;, 5000);<br \/>\n        manager.connect();<\/p>\n<p>        \/\/ \u521b\u5efa\u6301\u4e45\u8282\u70b9<br \/>\n        String nodePath &#061; manager.createNode(&#034;\/demoRoot&#034;, &#034;root data&#034;, CreateMode.PERSISTENT);<br \/>\n        System.out.println(&#034;Created: &#034; &#043; nodePath);<\/p>\n<p>        \/\/ \u521b\u5efa\u5b50\u8282\u70b9<br \/>\n        manager.createNode(&#034;\/demoRoot\/child1&#034;, &#034;child data&#034;, CreateMode.PERSISTENT);<\/p>\n<p>        \/\/ \u68c0\u67e5\u8282\u70b9\u662f\u5426\u5b58\u5728<br \/>\n        System.out.println(&#034;\/demoRoot exists: &#034; &#043; manager.exists(&#034;\/demoRoot&#034;));<\/p>\n<p>        \/\/ \u5220\u9664\u5b50\u8282\u70b9<br \/>\n        boolean deleted &#061; manager.deleteNode(&#034;\/demoRoot\/child1&#034;);<br \/>\n        System.out.println(&#034;Child deleted: &#034; &#043; deleted);<\/p>\n<p>        \/\/ \u9012\u5f52\u5220\u9664\u7236\u8282\u70b9<br \/>\n        manager.deleteRecursive(&#034;\/demoRoot&#034;);<\/p>\n<p>        manager.close();<br \/>\n    }<br \/>\n}<\/p>\n<h4>http:\/\/my.tv.sohu.com\/us\/445385256\/737670875.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/445385256\/737670954.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/445385256\/737670749.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/445385256\/737670911.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/445385256\/737670832.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/445385256\/737670382.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/445385256\/737670285.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/445385256\/737670360.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/445385256\/737670262.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/445385256\/737669895.shtml<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1Mzg1MjU2LzczNzY3MDg3NS5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1Mzg1MjU2LzczNzY3MDk1NC5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1Mzg1MjU2LzczNzY3MDc0OS5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1Mzg1MjU2LzczNzY3MDkxMS5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1Mzg1MjU2LzczNzY3MDgzMi5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1Mzg1MjU2LzczNzY3MDM4Mi5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1Mzg1MjU2LzczNzY3MDI4NS5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1Mzg1MjU2LzczNzY3MDM2MC5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1Mzg1MjU2LzczNzY3MDI2Mi5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1Mzg1MjU2LzczNzY2OTg5NS5zaHRtbA&#061;&#061;.html<br \/>\n&#xff0c;&#xff0c;&#xff0c;&#xff0c;<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/370099978\/737671903.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/370099978\/737671733.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/370099978\/737671823.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/370099978\/737671726.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/370099978\/737671718.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/370099978\/737671805.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/370099978\/737671400.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/370099978\/737671631.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/370099978\/737671702.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/370099978\/737671383.shtml<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvMzcwMDk5OTc4LzczNzY3MTkwMy5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvMzcwMDk5OTc4LzczNzY3MTczMy5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvMzcwMDk5OTc4LzczNzY3MTgyMy5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvMzcwMDk5OTc4LzczNzY3MTcyNi5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvMzcwMDk5OTc4LzczNzY3MTcxOC5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvMzcwMDk5OTc4LzczNzY3MTgwNS5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvMzcwMDk5OTc4LzczNzY3MTQwMC5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvMzcwMDk5OTc4LzczNzY3MTYzMS5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvMzcwMDk5OTc4LzczNzY3MTcwMi5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvMzcwMDk5OTc4LzczNzY3MTM4My5zaHRtbA&#061;&#061;.html<br \/>\n&#xff0c;&#xff0c;&#xff0c;&#xff0c;<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/445135000\/737672173.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/445135000\/737672342.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/445135000\/737672336.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/445135000\/737672333.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/445135000\/737672152.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/445135000\/737672239.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/445135000\/737672308.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/445135000\/737672132.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/445135000\/737672069.shtml<br \/>\nhttp:\/\/my.tv.sohu.com\/us\/445135000\/737672221.shtml<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1MTM1MDAwLzczNzY3MjE3My5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1MTM1MDAwLzczNzY3MjM0Mi5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1MTM1MDAwLzczNzY3MjMzNi5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1MTM1MDAwLzczNzY3MjMzMy5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1MTM1MDAwLzczNzY3MjE1Mi5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1MTM1MDAwLzczNzY3MjIzOS5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1MTM1MDAwLzczNzY3MjMwOC5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1MTM1MDAwLzczNzY3MjEzMi5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1MTM1MDAwLzczNzY3MjA2OS5zaHRtbA&#061;&#061;.html<br \/>\nhttps:\/\/tv.sohu.com\/v\/dXMvNDQ1MTM1MDAwLzczNzY3MjIyMS5zaHRtbA&#061;&#061;.html<\/h4>\n","protected":false},"excerpt":{"rendered":"<p>1. \u5f15\u8a00Apache ZooKeeper \u662f\u4e00\u4e2a\u5206\u5e03\u5f0f\u7684\u3001\u5f00\u653e\u6e90\u7801\u7684\u5206\u5e03\u5f0f\u5e94\u7528\u7a0b\u5e8f\u534f\u8c03\u670d\u52a1&#xff0c;\u662f Hadoop \u548c HBase \u7684\u91cd\u8981\u7ec4\u4ef6\u3002\u5b83\u4e3b\u8981\u7528\u4e8e\u89e3\u51b3\u5206\u5e03\u5f0f\u5e94\u7528\u4e2d\u7ecf\u5e38\u9047\u5230\u7684\u4e00\u4e9b\u6570\u636e\u7ba1\u7406\u95ee\u9898&#xff0c;\u5982\u7edf\u4e00\u547d\u540d\u670d\u52a1\u3001\u72b6\u6001\u540c\u6b65\u670d\u52a1\u3001\u96c6\u7fa4\u7ba1\u7406\u3001\u5206\u5e03\u5f0f\u5e94\u7528\u914d\u7f6e\u9879\u7684\u7ba1\u7406\u7b49\u3002ZooKeeper \u7684\u6570\u636e\u6a21\u578b\u91c7\u7528\u7c7b\u4f3c\u6587\u4ef6\u7cfb\u7edf\u7684\u6811\u72b6\u7ed3\u6784&#xff0c;\u6bcf\u4e2a\u8282\u70b9\u79f0\u4e3a\u4e00\u4e2a ZNode\u3002ZNode \u662f ZooKeeper \u4e2d\u6570\u636e\u5b58\u50a8\u7684\u57fa\u672c\u5355\u5143&#xff0c;\u53ef\u4ee5\u5b58\u50a8\u6570\u636e&amp;#x<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[99,1115,1898],"topic":[],"class_list":["post-95031","post","type-post","status-publish","format-standard","hentry","category-server","tag-java","tag-java-zookeeper","tag-zookeeper"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Zookeeper - Java API \u5b9e\u73b0\u8282\u70b9\u7684\u521b\u5efa\u4e0e\u5220\u9664\u5f00\u53d1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/95031.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Zookeeper - Java API \u5b9e\u73b0\u8282\u70b9\u7684\u521b\u5efa\u4e0e\u5220\u9664\u5f00\u53d1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"1. \u5f15\u8a00Apache ZooKeeper \u662f\u4e00\u4e2a\u5206\u5e03\u5f0f\u7684\u3001\u5f00\u653e\u6e90\u7801\u7684\u5206\u5e03\u5f0f\u5e94\u7528\u7a0b\u5e8f\u534f\u8c03\u670d\u52a1&#xff0c;\u662f Hadoop \u548c HBase \u7684\u91cd\u8981\u7ec4\u4ef6\u3002\u5b83\u4e3b\u8981\u7528\u4e8e\u89e3\u51b3\u5206\u5e03\u5f0f\u5e94\u7528\u4e2d\u7ecf\u5e38\u9047\u5230\u7684\u4e00\u4e9b\u6570\u636e\u7ba1\u7406\u95ee\u9898&#xff0c;\u5982\u7edf\u4e00\u547d\u540d\u670d\u52a1\u3001\u72b6\u6001\u540c\u6b65\u670d\u52a1\u3001\u96c6\u7fa4\u7ba1\u7406\u3001\u5206\u5e03\u5f0f\u5e94\u7528\u914d\u7f6e\u9879\u7684\u7ba1\u7406\u7b49\u3002ZooKeeper \u7684\u6570\u636e\u6a21\u578b\u91c7\u7528\u7c7b\u4f3c\u6587\u4ef6\u7cfb\u7edf\u7684\u6811\u72b6\u7ed3\u6784&#xff0c;\u6bcf\u4e2a\u8282\u70b9\u79f0\u4e3a\u4e00\u4e2a ZNode\u3002ZNode \u662f ZooKeeper \u4e2d\u6570\u636e\u5b58\u50a8\u7684\u57fa\u672c\u5355\u5143&#xff0c;\u53ef\u4ee5\u5b58\u50a8\u6570\u636e&amp;#x\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/95031.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-08-15T17:01:11+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"12 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/95031.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/95031.html\",\"name\":\"Zookeeper - Java API \u5b9e\u73b0\u8282\u70b9\u7684\u521b\u5efa\u4e0e\u5220\u9664\u5f00\u53d1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-08-15T17:01:11+00:00\",\"dateModified\":\"2026-08-15T17:01:11+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/95031.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/95031.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/95031.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Zookeeper - Java API \u5b9e\u73b0\u8282\u70b9\u7684\u521b\u5efa\u4e0e\u5220\u9664\u5f00\u53d1\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Zookeeper - Java API \u5b9e\u73b0\u8282\u70b9\u7684\u521b\u5efa\u4e0e\u5220\u9664\u5f00\u53d1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/95031.html","og_locale":"zh_CN","og_type":"article","og_title":"Zookeeper - Java API \u5b9e\u73b0\u8282\u70b9\u7684\u521b\u5efa\u4e0e\u5220\u9664\u5f00\u53d1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"1. \u5f15\u8a00Apache ZooKeeper \u662f\u4e00\u4e2a\u5206\u5e03\u5f0f\u7684\u3001\u5f00\u653e\u6e90\u7801\u7684\u5206\u5e03\u5f0f\u5e94\u7528\u7a0b\u5e8f\u534f\u8c03\u670d\u52a1&#xff0c;\u662f Hadoop \u548c HBase \u7684\u91cd\u8981\u7ec4\u4ef6\u3002\u5b83\u4e3b\u8981\u7528\u4e8e\u89e3\u51b3\u5206\u5e03\u5f0f\u5e94\u7528\u4e2d\u7ecf\u5e38\u9047\u5230\u7684\u4e00\u4e9b\u6570\u636e\u7ba1\u7406\u95ee\u9898&#xff0c;\u5982\u7edf\u4e00\u547d\u540d\u670d\u52a1\u3001\u72b6\u6001\u540c\u6b65\u670d\u52a1\u3001\u96c6\u7fa4\u7ba1\u7406\u3001\u5206\u5e03\u5f0f\u5e94\u7528\u914d\u7f6e\u9879\u7684\u7ba1\u7406\u7b49\u3002ZooKeeper \u7684\u6570\u636e\u6a21\u578b\u91c7\u7528\u7c7b\u4f3c\u6587\u4ef6\u7cfb\u7edf\u7684\u6811\u72b6\u7ed3\u6784&#xff0c;\u6bcf\u4e2a\u8282\u70b9\u79f0\u4e3a\u4e00\u4e2a ZNode\u3002ZNode \u662f ZooKeeper \u4e2d\u6570\u636e\u5b58\u50a8\u7684\u57fa\u672c\u5355\u5143&#xff0c;\u53ef\u4ee5\u5b58\u50a8\u6570\u636e&amp;#x","og_url":"https:\/\/www.wsisp.com\/helps\/95031.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-08-15T17:01:11+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"12 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/95031.html","url":"https:\/\/www.wsisp.com\/helps\/95031.html","name":"Zookeeper - Java API \u5b9e\u73b0\u8282\u70b9\u7684\u521b\u5efa\u4e0e\u5220\u9664\u5f00\u53d1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-08-15T17:01:11+00:00","dateModified":"2026-08-15T17:01:11+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/95031.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/95031.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/95031.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Zookeeper - Java API \u5b9e\u73b0\u8282\u70b9\u7684\u521b\u5efa\u4e0e\u5220\u9664\u5f00\u53d1"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/95031","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=95031"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/95031\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=95031"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=95031"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=95031"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=95031"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}