Zookeeper实现的分布式锁的示例代码: public class DistributedLock { private static final String LOCK_BASE_PATH = "/distributed-lock
Lock接口有一套自己的实现,zookeeper的Lock接口也有自己的一套实现,redis...各种分布式锁实现方案都有自己的Lock,因此,我封装了一个模板方法: /** * @program: distributed-lock "线程:{} 释放锁", currentThread.getName()); } 解锁过程: 重入性检查 移除当前锁的节点路径释放锁 清除重入的线程资源 接口测试 /** * @program: distributed-lock
upstream distributed-lock { server 192.168.2.1:8080 weight=1; server 192.168.2.1:8090 weight= location / { root html; index index.html index.htm; proxy_pass http://distributed-lock
performance-optimization,caching,api-design,frontend-backend-separation,state-management,persistence-layer,distributed-lock
相关代码 gitee: distributed-lock 来源: https://www.toutiao.com/i6945048449087750688/
DistributedLockDemo { // ZooKeeper 锁节点路径, 分布式锁的相关操作都是在这个节点上进行 private final String lockPath = "/distributed-lock
---- 代码实现 代码库 https://github.com/HuTu92/distributed-lock 源码 package com.github.hutu92.concurrent.locks