最近写了一个分布式锁
https://github.com/majinliang123/messtin-lock
功能如下:
例子
public class Example1 { public static void main(String[] args) throws InterruptedException { LockClient client = LockClient.newInstance("localhost"); try { client.lock("1"); System.out.println("1"); } finally { client.release("1"); } } }
Tech
- 使用netty进行长连接
- 当某个client下线,会被server检测到,从而释放锁