You need to enable JavaScript to run this app.
文档中心
湖仓一体分析服务 LAS 私有化

湖仓一体分析服务 LAS 私有化

复制全文
下载 pdf
Zookeeper
进阶使用
复制全文
下载 pdf
进阶使用

以下提供一个简单的 Java 示例,用于展示如何建立 ZK 连接以及列出 ZK 中的节点。
再次提示:为了保证集群的稳定性,不建议使用 ZK 进行自行编程。

public class ZkTest {
    public static void main(String[] args) throws IOException {
        String hostPort = "localhost:2181";
        List<String> zooChildren = new ArrayList<String>();
        ZooKeeper zk = new ZooKeeper(hostPort, 2000, null);
        if (zk != null) {
            try {
                String zpath = "/";
                zooChildren = zk.getChildren(zpath, false);
                System.out.println("Znodes of '/': ");
                for (String child : zooChildren) {
                    System.out.println(child);
                }
            }  catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

其余操作可自行查看 Zookeeper 类提供的方法进行调用。

最近更新时间:2025.04.01 20:13:40
这个页面对您有帮助吗?
有用
有用
无用
无用