语法关键字的锁synchronize
RetrantLock
ReadWriteLock,独占锁,共享锁
分布式锁,zookeeper中的锁,redis setnx锁,redLock锁
数据库锁,独占锁,共享锁
行级锁
begin; select * from table where id=1 for update;//id主键,查到数据,行级锁,差不多数据不锁
表级锁
begin; select * from table where customerID ='0010075476966' for UPDATE;//customerID非主键,查到数据。表级锁,查不查到数据都锁
Curator netflix公司开发,zookeeper客户端
创建启动客户端
Retrypolicy retrypolicy = new RetryUntilElaped(5000, 1000)
CuratorFrameworkFactory.newClient("127.0.0.1:2181,127.0.0.1:2182", sessiontimeout,connectiontimeout,retrypolicy)
client.start();
new InterProcessMutex(client, "bit").acquire() //加锁时bit节点下生成瞬时有序节点,判断请求生成的节点时最小节点即得锁
包括InterProcessMutex锁 InterProcessReadWriteLock读写锁 InterProcessSemphore信号量