Apache zookeeper 策展人:进程间互斥锁。release()没有';t删除锁定路径
Apache zookeeper 策展人:进程间互斥锁。release()没有';t删除锁定路径,apache-zookeeper,apache-curator,Apache Zookeeper,Apache Curator,Lock.release()是否不删除锁定路径?这是虫子吗? 我需要自己删除路径吗 RetryPolicy retryPolicy = new RetryOneTime(1000); CuratorFramework client = CuratorFrameworkFactory .builder() .connectString(zkAddress) .se
Lock.release()
是否不删除锁定路径?这是虫子吗?
我需要自己删除路径吗
RetryPolicy retryPolicy = new RetryOneTime(1000);
CuratorFramework client =
CuratorFrameworkFactory
.builder()
.connectString(zkAddress)
.sessionTimeoutMs(ZKConstant.ZK_SESSION_TIMEOUT)
.connectionTimeoutMs(ZKConstant.ZK_CONNECTION_TIMEOUT)
.retryPolicy(retryPolicy)
.build();
client.start();
InterProcessMutex lock = new InterProcessMutex(client, "/test_lock");
if (lock.acquire(3, TimeUnit.SECONDS)) {
LOGGER.debug(curatorUtil.exists(lockPath) == null);
}
if (lock != null){
lock.release(); // After I call this method,
// the "/test_lock" node still exists. Why?
}
LOGGER.debug(curatorUtil.exists(lockPath) == null);
client.close();
} catch (Exception e) {
e.printStackTrace();
}
}
是!父节点不会自动删除。因为实际创建的节点如下所示
/test_lock/"+"_c_"+UUID.randomUUID().toString()+"-"
看
之后
子节点将被删除。这是ZooKeeper中的一个常见问题。这就是我在ZooKeeper 3.5中添加容器节点的原因。如果使用Curator 3.0和ZooKeeper 3.5.x,父节点将自动删除。在旧版本中,您需要使用馆长的收割机和ChidReaper。
CreateBuilderImpl#adjustPath
lock.release()