为什么需要分布式锁
订单号的生产问题?所有需要引入第三者来协调产生订单的顺序,保证唯一性,即争夺共享资源,需要分布式锁
引入zookeeper中间件
利用zookeeper节点特效,有序性产生不会冲突的资源
实现逻辑设计
具体代码实现
maven项目引入
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.13</version>
</dependency>
代码实现
public class DistributeLock {
private static final String CONNECT_IP_PORT = "176.16.0.135:2181";
private static final Logger logger = LoggerFactory.getLogger(DistributeLock.class);
private ZooKeeper zooKeeper;
private final int sessionTimeout = 5000;
private final String ROOT_LOCKS = "/LOCKS";
private final byte[] data = {1, 2, 3};
private String lockId;
private CountDownLatch lessNodeDeleteLatch = new CountDownLatch(1);
public DistributeLock() {
this.zooKeeper = getInstance();
}
// 【核心方法】:获取锁
public boolean lock() {
try {
lockId = zooKeeper.create(ROOT_LOCKS + "/", data, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL);
logger.debug("2.{}:成功创建lock节点[{}], 开始竞争锁", Thread.currentThread().getName(), lockId);
// 竞争共享锁
List<String> childrens = zooKeeper.getChildren(ROOT_LOCKS, true);
SortedSet<String> sortedSet = new TreeSet<>(childrens);
// 当前LOCKS子节点最小节点
String absolutePath = ROOT_LOCKS + "/" + sortedSet.first();
if (lockId.equals(absolutePath)) {
logger.debug("3.{}:成功获取锁,锁节点为:{}", Thread.currentThread().getName(), lockId);
return true;
}
// 返回此 set 的部分视图,其元素严格小于 toElement。
SortedSet<String> lessLockIdSet = sortedSet.headSet(lockId.substring(lockId.lastIndexOf("/") + 1));
if (!lessLockIdSet.isEmpty()) {
String last = lessLockIdSet.last();
String lessAbsolutePath = ROOT_LOCKS + "/" + last;
zooKeeper.exists(lessAbsolutePath, new LockWatcher(lessNodeDeleteLatch));
logger.debug("4.{}:未获取锁,监听比当前锁更小的节点:{}", Thread.currentThread().getName(), lessAbsolutePath);
lessNodeDeleteLatch.await(sessionTimeout, TimeUnit.MILLISECONDS);
logger.debug("5.{}:成功获取锁,锁节点为:{}", Thread.currentThread().getName(), lockId);
}
} catch (KeeperException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
return false;
}
// 【核心方法】:释放锁
public boolean unlock() {
logger.debug("6.{}:开始释放锁,锁节点为:{}", Thread.currentThread().getName(), lockId);
try {
zooKeeper.delete(lockId, -1);
logger.debug("7.{}:释放锁成功,锁节点为:{}", Thread.currentThread().getName(), lockId);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (KeeperException e) {
e.printStackTrace();
}
return false;
}
private ZooKeeper getInstance() {
ZooKeeper zooKeeper = null;
CountDownLatch countDownLatch = new CountDownLatch(1);
try {
zooKeeper = new ZooKeeper(CONNECT_IP_PORT, sessionTimeout, new Watcher() {
@Override
public void process(WatchedEvent event) {
logger.debug("连接zookeeper成功:{}", event.getState());
countDownLatch.countDown();
}
});
countDownLatch.await();
logger.debug("1.创建zooKeeper对象成功:{}", zooKeeper.getState());
} catch (IOException e) {
} catch (InterruptedException e) {
}
return zooKeeper;
}
public static void main(String[] args) {
CountDownLatch runLatch = new CountDownLatch(10);
for (int i = 0; i < 10 ; i++) {
new Thread(()->{
DistributeLock distributeLock = null;
try {
distributeLock = new DistributeLock();
runLatch.countDown();
// 所有进程都等着,都准备好了一起开始抢
runLatch.await();
distributeLock.lock();
TimeUnit.MILLISECONDS.sleep(new Random().nextInt(500));
} catch (Exception e) {
e.printStackTrace();
} finally {
if (distributeLock != null) {
distributeLock.unlock();
}
}
}).start();;
}
}
}
删除监听事件
public class LockWatcher implements Watcher {
private CountDownLatch latch;
public LockWatcher(CountDownLatch latch) {
this.latch = latch;
}
@Override
public void process(WatchedEvent event) {
if (event.getType() == EventType.NodeDeleted) {
latch.countDown();
}
}
}
测试结果
连接zookeeper成功:SyncConnected
Session establishment complete on server 176.16.0.135/176.16.0.135:2181, sessionid = 0x1000002273d0003, negotiated timeout = 5000
连接zookeeper成功:SyncConnected
1.创建zooKeeper对象成功:CONNECTED
1.创建zooKeeper对象成功:CONNECTED
连接zookeeper成功:SyncConnected
1.创建zooKeeper对象成功:CONNECTED
Session establishment complete on server 176.16.0.135/176.16.0.135:2181, sessionid = 0x1000002273d0004, negotiated timeout = 5000
连接zookeeper成功:SyncConnected
1.创建zooKeeper对象成功:CONNECTED
Session establishment complete on server 176.16.0.135/176.16.0.135:2181, sessionid = 0x1000002273d0005, negotiated timeout = 5000
连接zookeeper成功:SyncConnected
1.创建zooKeeper对象成功:CONNECTED
Session establishment complete on server 176.16.0.135/176.16.0.135:2181, sessionid = 0x1000002273d0006, negotiated timeout = 5000
连接zookeeper成功:SyncConnected
1.创建zooKeeper对象成功:CONNECTED
Session establishment complete on server 176.16.0.135/176.16.0.135:2181, sessionid = 0x1000002273d0007, negotiated timeout = 5000
连接zookeeper成功:SyncConnected
1.创建zooKeeper对象成功:CONNECTED
Session establishment complete on server 176.16.0.135/176.16.0.135:2181, sessionid = 0x1000002273d0008, negotiated timeout = 5000
连接zookeeper成功:SyncConnected
1.创建zooKeeper对象成功:CONNECTED
Session establishment complete on server 176.16.0.135/176.16.0.135:2181, sessionid = 0x1000002273d0009, negotiated timeout = 5000
连接zookeeper成功:SyncConnected
1.创建zooKeeper对象成功:CONNECTED
Session establishment complete on server 176.16.0.135/176.16.0.135:2181, sessionid = 0x1000002273d000a, negotiated timeout = 5000
连接zookeeper成功:SyncConnected
1.创建zooKeeper对象成功:CONNECTED
Reading reply sessionid:0x1000002273d000a, packet:: clientPath:null serverPath:null finished:false header:: 1,1 replyHeader:: 1,28386,0 request:: '/LOCKS/,#123,v{s{31,s{'world,'anyone}}},3 response:: '/LOCKS/0000000012
Reading reply sessionid:0x1000002273d0001, packet:: clientPath:null serverPath:null finished:false header:: 1,1 replyHeader:: 1,28387,0 request:: '/LOCKS/,#123,v{s{31,s{'world,'anyone}}},3 response:: '/LOCKS/0000000013
Reading reply sessionid:0x1000002273d0005, packet:: clientPath:null serverPath:null finished:false header:: 1,1 replyHeader:: 1,28385,0 request:: '/LOCKS/,#123,v{s{31,s{'world,'anyone}}},3 response:: '/LOCKS/0000000011
Reading reply sessionid:0x1000002273d0008, packet:: clientPath:null serverPath:null finished:false header:: 1,1 replyHeader:: 1,28388,0 request:: '/LOCKS/,#123,v{s{31,s{'world,'anyone}}},3 response:: '/LOCKS/0000000014
Reading reply sessionid:0x1000002273d0002, packet:: clientPath:null serverPath:null finished:false header:: 1,1 replyHeader:: 1,28384,0 request:: '/LOCKS/,#123,v{s{31,s{'world,'anyone}}},3 response:: '/LOCKS/0000000010
2.Thread-1:成功创建lock节点[/LOCKS/0000000012], 开始竞争锁
2.Thread-7:成功创建lock节点[/LOCKS/0000000011], 开始竞争锁
2.Thread-3:成功创建lock节点[/LOCKS/0000000014], 开始竞争锁
2.Thread-4:成功创建lock节点[/LOCKS/0000000010], 开始竞争锁
2.Thread-8:成功创建lock节点[/LOCKS/0000000013], 开始竞争锁
Reading reply sessionid:0x1000002273d0007, packet:: clientPath:null serverPath:null finished:false header:: 1,1 replyHeader:: 1,28390,0 request:: '/LOCKS/,#123,v{s{31,s{'world,'anyone}}},3 response:: '/LOCKS/0000000016
Reading reply sessionid:0x1000002273d0009, packet:: clientPath:null serverPath:null finished:false header:: 1,1 replyHeader:: 1,28389,0 request:: '/LOCKS/,#123,v{s{31,s{'world,'anyone}}},3 response:: '/LOCKS/0000000015
2.Thread-6:成功创建lock节点[/LOCKS/0000000016], 开始竞争锁
2.Thread-2:成功创建lock节点[/LOCKS/0000000015], 开始竞争锁
Reading reply sessionid:0x1000002273d0004, packet:: clientPath:null serverPath:null finished:false header:: 1,1 replyHeader:: 1,28391,0 request:: '/LOCKS/,#123,v{s{31,s{'world,'anyone}}},3 response:: '/LOCKS/0000000017
Reading reply sessionid:0x1000002273d0003, packet:: clientPath:null serverPath:null finished:false header:: 1,1 replyHeader:: 1,28392,0 request:: '/LOCKS/,#123,v{s{31,s{'world,'anyone}}},3 response:: '/LOCKS/0000000018
2.Thread-0:成功创建lock节点[/LOCKS/0000000017], 开始竞争锁
2.Thread-5:成功创建lock节点[/LOCKS/0000000018], 开始竞争锁
Reading reply sessionid:0x1000002273d0006, packet:: clientPath:null serverPath:null finished:false header:: 1,1 replyHeader:: 1,28393,0 request:: '/LOCKS/,#123,v{s{31,s{'world,'anyone}}},3 response:: '/LOCKS/0000000019
2.Thread-9:成功创建lock节点[/LOCKS/0000000019], 开始竞争锁
Reading reply sessionid:0x1000002273d0001, packet:: clientPath:null serverPath:null finished:false header:: 2,8 replyHeader:: 2,28393,0 request:: '/LOCKS,T response:: v{'0000000012,'0000000011,'0000000014,'0000000013,'0000000016,'0000000015,'0000000018,'0000000017,'0000000019,'0000000010}
Reading reply sessionid:0x1000002273d000a, packet:: clientPath:null serverPath:null finished:false header:: 2,8 replyHeader:: 2,28393,0 request:: '/LOCKS,T response:: v{'0000000012,'0000000011,'0000000014,'0000000013,'0000000016,'0000000015,'0000000018,'0000000017,'0000000019,'0000000010}
Reading reply sessionid:0x1000002273d0007, packet:: clientPath:null serverPath:null finished:false header:: 2,8 replyHeader:: 2,28393,0 request:: '/LOCKS,T response:: v{'0000000012,'0000000011,'0000000014,'0000000013,'0000000016,'0000000015,'0000000018,'0000000017,'0000000019,'0000000010}
Reading reply sessionid:0x1000002273d0002, packet:: clientPath:null serverPath:null finished:false header:: 2,8 replyHeader:: 2,28393,0 request:: '/LOCKS,T response:: v{'0000000012,'0000000011,'0000000014,'0000000013,'0000000016,'0000000015,'0000000018,'0000000017,'0000000019,'0000000010}
3.Thread-4:成功获取锁,锁节点为:/LOCKS/0000000010
Reading reply sessionid:0x1000002273d0009, packet:: clientPath:null serverPath:null finished:false header:: 2,8 replyHeader:: 2,28393,0 request:: '/LOCKS,T response:: v{'0000000012,'0000000011,'0000000014,'0000000013,'0000000016,'0000000015,'0000000018,'0000000017,'0000000019,'0000000010}
Reading reply sessionid:0x1000002273d0005, packet:: clientPath:null serverPath:null finished:false header:: 2,8 replyHeader:: 2,28393,0 request:: '/LOCKS,T response:: v{'0000000012,'0000000011,'0000000014,'0000000013,'0000000016,'0000000015,'0000000018,'0000000017,'0000000019,'0000000010}
Reading reply sessionid:0x1000002273d0008, packet:: clientPath:null serverPath:null finished:false header:: 2,8 replyHeader:: 2,28393,0 request:: '/LOCKS,T response:: v{'0000000012,'0000000011,'0000000014,'0000000013,'0000000016,'0000000015,'0000000018,'0000000017,'0000000019,'0000000010}
Reading reply sessionid:0x1000002273d0004, packet:: clientPath:null serverPath:null finished:false header:: 2,8 replyHeader:: 2,28393,0 request:: '/LOCKS,T response:: v{'0000000012,'0000000011,'0000000014,'0000000013,'0000000016,'0000000015,'0000000018,'0000000017,'0000000019,'0000000010}
Reading reply sessionid:0x1000002273d0003, packet:: clientPath:null serverPath:null finished:false header:: 2,8 replyHeader:: 2,28393,0 request:: '/LOCKS,T response:: v{'0000000012,'0000000011,'0000000014,'0000000013,'0000000016,'0000000015,'0000000018,'0000000017,'0000000019,'0000000010}
Reading reply sessionid:0x1000002273d0006, packet:: clientPath:null serverPath:null finished:false header:: 2,8 replyHeader:: 2,28393,0 request:: '/LOCKS,T response:: v{'0000000012,'0000000011,'0000000014,'0000000013,'0000000016,'0000000015,'0000000018,'0000000017,'0000000019,'0000000010}
Reading reply sessionid:0x1000002273d000a, packet:: clientPath:null serverPath:null finished:false header:: 3,3 replyHeader:: 3,28393,0 request:: '/LOCKS/0000000011,T response:: s{28385,28385,1548055011348,1548055011348,0,0,0,72057603286171653,3,0,28385}
Reading reply sessionid:0x1000002273d0009, packet:: clientPath:null serverPath:null finished:false header:: 3,3 replyHeader:: 3,28393,0 request:: '/LOCKS/0000000014,T response:: s{28388,28388,1548055011349,1548055011349,0,0,0,72057603286171656,3,0,28388}
4.Thread-1:未获取锁,监听比当前锁更小的节点:/LOCKS/0000000011
Reading reply sessionid:0x1000002273d0001, packet:: clientPath:null serverPath:null finished:false header:: 3,3 replyHeader:: 3,28393,0 request:: '/LOCKS/0000000012,T response:: s{28386,28386,1548055011348,1548055011348,0,0,0,72057603286171658,3,0,28386}
4.Thread-2:未获取锁,监听比当前锁更小的节点:/LOCKS/0000000014
4.Thread-8:未获取锁,监听比当前锁更小的节点:/LOCKS/0000000012
Reading reply sessionid:0x1000002273d0005, packet:: clientPath:null serverPath:null finished:false header:: 3,3 replyHeader:: 3,28393,0 request:: '/LOCKS/0000000010,T response:: s{28384,28384,1548055011255,1548055011255,0,0,0,72057603286171650,3,0,28384}
4.Thread-7:未获取锁,监听比当前锁更小的节点:/LOCKS/0000000010
Reading reply sessionid:0x1000002273d0007, packet:: clientPath:null serverPath:null finished:false header:: 3,3 replyHeader:: 3,28393,0 request:: '/LOCKS/0000000015,T response:: s{28389,28389,1548055011349,1548055011349,0,0,0,72057603286171657,3,0,28389}
Reading reply sessionid:0x1000002273d0003, packet:: clientPath:null serverPath:null finished:false header:: 3,3 replyHeader:: 3,28393,0 request:: '/LOCKS/0000000017,T response:: s{28391,28391,1548055011349,1548055011349,0,0,0,72057603286171652,3,0,28391}
Reading reply sessionid:0x1000002273d0004, packet:: clientPath:null serverPath:null finished:false header:: 3,3 replyHeader:: 3,28393,0 request:: '/LOCKS/0000000016,T response:: s{28390,28390,1548055011349,1548055011349,0,0,0,72057603286171655,3,0,28390}
Reading reply sessionid:0x1000002273d0008, packet:: clientPath:null serverPath:null finished:false header:: 3,3 replyHeader:: 3,28393,0 request:: '/LOCKS/0000000013,T response:: s{28387,28387,1548055011349,1548055011349,0,0,0,72057603286171649,3,0,28387}
4.Thread-6:未获取锁,监听比当前锁更小的节点:/LOCKS/0000000015
4.Thread-5:未获取锁,监听比当前锁更小的节点:/LOCKS/0000000017
4.Thread-3:未获取锁,监听比当前锁更小的节点:/LOCKS/0000000013
4.Thread-0:未获取锁,监听比当前锁更小的节点:/LOCKS/0000000016
Reading reply sessionid:0x1000002273d0006, packet:: clientPath:null serverPath:null finished:false header:: 3,3 replyHeader:: 3,28393,0 request:: '/LOCKS/0000000018,T response:: s{28392,28392,1548055011349,1548055011349,0,0,0,72057603286171651,3,0,28392}
4.Thread-9:未获取锁,监听比当前锁更小的节点:/LOCKS/0000000018
6.Thread-4:开始释放锁,锁节点为:/LOCKS/0000000010
Got notification sessionid:0x1000002273d0005
Got notification sessionid:0x1000002273d000a
Got WatchedEvent state:SyncConnected type:NodeChildrenChanged path:/LOCKS for sessionid 0x1000002273d000a
Got WatchedEvent state:SyncConnected type:NodeDeleted path:/LOCKS/0000000010 for sessionid 0x1000002273d0005
连接zookeeper成功:SyncConnected
5.Thread-7:成功获取锁,锁节点为:/LOCKS/0000000011
Got notification sessionid:0x1000002273d0005
Got WatchedEvent state:SyncConnected type:NodeChildrenChanged path:/LOCKS for sessionid 0x1000002273d0005
Got notification sessionid:0x1000002273d0004
连接zookeeper成功:SyncConnected
Got WatchedEvent state:SyncConnected type:NodeChildrenChanged path:/LOCKS for sessionid 0x1000002273d0004
连接zookeeper成功:SyncConnected
Got notification sessionid:0x1000002273d0007
Got notification sessionid:0x1000002273d0002
Got WatchedEvent state:SyncConnected type:NodeChildrenChanged path:/LOCKS for sessionid 0x1000002273d0002
Got WatchedEvent state:SyncConnected type:NodeChildrenChanged path:/LOCKS for sessionid 0x1000002273d0007
连接zookeeper成功:SyncConnected
连接zookeeper成功:SyncConnected
Got notification sessionid:0x1000002273d0009
Got notification sessionid:0x1000002273d0001
Got WatchedEvent state:SyncConnected type:NodeChildrenChanged path:/LOCKS for sessionid 0x1000002273d0001
Got WatchedEvent state:SyncConnected type:NodeChildrenChanged path:/LOCKS for sessionid 0x1000002273d0009
连接zookeeper成功:SyncConnected
连接zookeeper成功:SyncConnected
Got notification sessionid:0x1000002273d0008
Got notification sessionid:0x1000002273d0006
Got WatchedEvent state:SyncConnected type:NodeChildrenChanged path:/LOCKS for sessionid 0x1000002273d0006
Got notification sessionid:0x1000002273d0003
Got WatchedEvent state:SyncConnected type:NodeChildrenChanged path:/LOCKS for sessionid 0x1000002273d0008
连接zookeeper成功:SyncConnected
Got WatchedEvent state:SyncConnected type:NodeChildrenChanged path:/LOCKS for sessionid 0x1000002273d0003
连接zookeeper成功:SyncConnected
连接zookeeper成功:SyncConnected
Reading reply sessionid:0x1000002273d0002, packet:: clientPath:null serverPath:null finished:false header:: 3,2 replyHeader:: 3,28394,0 request:: '/LOCKS/0000000010,-1 response:: null
7.Thread-4:释放锁成功,锁节点为:/LOCKS/0000000010
6.Thread-7:开始释放锁,锁节点为:/LOCKS/0000000011
Got notification sessionid:0x1000002273d000a
Got WatchedEvent state:SyncConnected type:NodeDeleted path:/LOCKS/0000000011 for sessionid 0x1000002273d000a
Reading reply sessionid:0x1000002273d0005, packet:: clientPath:null serverPath:null finished:false header:: 4,2 replyHeader:: 4,28395,0 request:: '/LOCKS/0000000011,-1 response:: null
7.Thread-7:释放锁成功,锁节点为:/LOCKS/0000000011
5.Thread-1:成功获取锁,锁节点为:/LOCKS/0000000012
6.Thread-1:开始释放锁,锁节点为:/LOCKS/0000000012
Got notification sessionid:0x1000002273d0001
Got WatchedEvent state:SyncConnected type:NodeDeleted path:/LOCKS/0000000012 for sessionid 0x1000002273d0001
5.Thread-8:成功获取锁,锁节点为:/LOCKS/0000000013
Reading reply sessionid:0x1000002273d000a, packet:: clientPath:null serverPath:null finished:false header:: 4,2 replyHeader:: 4,28396,0 request:: '/LOCKS/0000000012,-1 response:: null
7.Thread-1:释放锁成功,锁节点为:/LOCKS/0000000012
6.Thread-8:开始释放锁,锁节点为:/LOCKS/0000000013
Got notification sessionid:0x1000002273d0008
Got WatchedEvent state:SyncConnected type:NodeDeleted path:/LOCKS/0000000013 for sessionid 0x1000002273d0008
5.Thread-3:成功获取锁,锁节点为:/LOCKS/0000000014
Reading reply sessionid:0x1000002273d0001, packet:: clientPath:null serverPath:null finished:false header:: 4,2 replyHeader:: 4,28397,0 request:: '/LOCKS/0000000013,-1 response:: null
7.Thread-8:释放锁成功,锁节点为:/LOCKS/0000000013
6.Thread-3:开始释放锁,锁节点为:/LOCKS/0000000014
Got notification sessionid:0x1000002273d0009
Got WatchedEvent state:SyncConnected type:NodeDeleted path:/LOCKS/0000000014 for sessionid 0x1000002273d0009
Reading reply sessionid:0x1000002273d0008, packet:: clientPath:null serverPath:null finished:false header:: 4,2 replyHeader:: 4,28398,0 request:: '/LOCKS/0000000014,-1 response:: null
7.Thread-3:释放锁成功,锁节点为:/LOCKS/0000000014
5.Thread-2:成功获取锁,锁节点为:/LOCKS/0000000015
6.Thread-2:开始释放锁,锁节点为:/LOCKS/0000000015
Got notification sessionid:0x1000002273d0007
Got WatchedEvent state:SyncConnected type:NodeDeleted path:/LOCKS/0000000015 for sessionid 0x1000002273d0007
5.Thread-6:成功获取锁,锁节点为:/LOCKS/0000000016
Reading reply sessionid:0x1000002273d0009, packet:: clientPath:null serverPath:null finished:false header:: 4,2 replyHeader:: 4,28399,0 request:: '/LOCKS/0000000015,-1 response:: null
7.Thread-2:释放锁成功,锁节点为:/LOCKS/0000000015
Got ping response for sessionid: 0x1000002273d0009 after 10ms
Got ping response for sessionid: 0x1000002273d0007 after 5ms
6.Thread-6:开始释放锁,锁节点为:/LOCKS/0000000016
Got notification sessionid:0x1000002273d0004
Got WatchedEvent state:SyncConnected type:NodeDeleted path:/LOCKS/0000000016 for sessionid 0x1000002273d0004
Reading reply sessionid:0x1000002273d0007, packet:: clientPath:null serverPath:null finished:false header:: 4,2 replyHeader:: 4,28400,0 request:: '/LOCKS/0000000016,-1 response:: null
7.Thread-6:释放锁成功,锁节点为:/LOCKS/0000000016
5.Thread-0:成功获取锁,锁节点为:/LOCKS/0000000017
Got ping response for sessionid: 0x1000002273d0004 after 5ms
Got ping response for sessionid: 0x1000002273d0003 after 1ms
Got ping response for sessionid: 0x1000002273d0006 after 1ms
Got ping response for sessionid: 0x1000002273d0002 after 1ms
6.Thread-0:开始释放锁,锁节点为:/LOCKS/0000000017
Got notification sessionid:0x1000002273d0003
Got WatchedEvent state:SyncConnected type:NodeDeleted path:/LOCKS/0000000017 for sessionid 0x1000002273d0003
Reading reply sessionid:0x1000002273d0004, packet:: clientPath:null serverPath:null finished:false header:: 4,2 replyHeader:: 4,28401,0 request:: '/LOCKS/0000000017,-1 response:: null
7.Thread-0:释放锁成功,锁节点为:/LOCKS/0000000017
5.Thread-5:成功获取锁,锁节点为:/LOCKS/0000000018
6.Thread-5:开始释放锁,锁节点为:/LOCKS/0000000018
Got notification sessionid:0x1000002273d0006
Got WatchedEvent state:SyncConnected type:NodeDeleted path:/LOCKS/0000000018 for sessionid 0x1000002273d0006
5.Thread-9:成功获取锁,锁节点为:/LOCKS/0000000019
Reading reply sessionid:0x1000002273d0003, packet:: clientPath:null serverPath:null finished:false header:: 4,2 replyHeader:: 4,28402,0 request:: '/LOCKS/0000000018,-1 response:: null
7.Thread-5:释放锁成功,锁节点为:/LOCKS/0000000018
Got ping response for sessionid: 0x1000002273d0005 after 2ms
Got ping response for sessionid: 0x1000002273d000a after 4ms
Got ping response for sessionid: 0x1000002273d0001 after 4ms
6.Thread-9:开始释放锁,锁节点为:/LOCKS/0000000019
Reading reply sessionid:0x1000002273d0006, packet:: clientPath:null serverPath:null finished:false header:: 4,2 replyHeader:: 4,28403,0 request:: '/LOCKS/0000000019,-1 response:: null
7.Thread-9:释放锁成功,锁节点为:/LOCKS/0000000019