package cn.ssy.zk.api;
import java.util.List;
import org.apache.zookeeper.ZooKeeper;
public class ZKAPIDemoTest {
private static String connectString ="hadoop02:2181";
private static int sessionTimeout=5000;
public static void main(String[] args) throws Exception {
//创建节点
ZooKeeper zk = new ZooKeeper(connectString, sessionTimeout, null);
rmr("/zk01");
zk.close();
}
public static boolean rmr(String path) throws Exception{
ZooKeeper zk = new ZooKeeper(connectString, sessionTimeout, null);
String childrenPath = null;
List<String> children = zk.getChildren(path, false);
if (children.size()!=0){
for(String child: children){
childrenPath=path+"/"+child;
if(childrenPath.isEmpty()){
zk.delete(childrenPath, -1);
}else rmr(childrenPath);
System.out.println(childrenPath);
}
}
zk.delete(path, -1);
return false;
}
}
ZooKeeper级联删除javaAPI
最新推荐文章于 2024-01-02 21:54:13 发布