Jos*_*ose 8 java apache-zookeeper apache-curator
有谁知道Curator锁配方中的哪一个会产生短暂的节点?
我测试了InterProcessMutex锁,但据我所知(使用zkClient),它不会在释放后删除节点或关闭会话.
这是我用于锁定密钥的代码.
public void lock(final LockKey lockkey, final LockAcquiredListener listener) throws Exception {
final String lockKeyPath = lockkey.toString();
LOGGER.info("Trying to acquire the lock {}", lockKeyPath);
final InterProcessMutex lock = new InterProcessMutex(client, LOCKS_PREFIX + lockKeyPath);
if (!lock.acquire(LOCK_MS_TIME_OUT, TimeUnit.MILLISECONDS)) {
LOGGER.info("Could not acquire the lock {}", lockkey.toString());
throw new LockAcquisitionTimeOutException("Could not acquire the lock: " + lockKeyPath);
}
try {
if (listener != null) {
LOGGER.info("Lock acquired for key {}", lockKeyPath);
listener.lockAcquired(lockkey);
}
} finally {
LOGGER.info("Release acquired key {}", lockKeyPath);
lock.release();
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢!
| 归档时间: |
|
| 查看次数: |
712 次 |
| 最近记录: |