策展人:InterProcessMutex Lock.release()没有删除锁定路径

时间:2016-10-19 11:41:09

标签: apache-zookeeper apache-curator

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();
    }
}

1 个答案:

答案 0 :(得分:0)

是!父节点不会自动删除。因为实际创建的节点是这样的

/test_lock/"+"_c_"+UUID.randomUUID().toString()+"-"

外观

CreateBuilderImpl#adjustPath

lock.release()

将删除子节点。