当前位置:网站首页>Distributed lock development
Distributed lock development
2022-07-30 08:09:00 【weixin_45031570】
Redisson分布式锁
搭建
maven
<!-- https://mvnrepository.com/artifact/org.redisson/redisson -->
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson</artifactId>
<version>3.12.0</version>
</dependency>
Build in single instance mode
github地址
https://github.com/redisson/redisson/wiki/2.-Configuration
配置类,加入ioc容器
// connects to 127.0.0.1:6379 by default
RedissonClient redisson = Redisson.create();
Config config = new Config();
config.useSingleServer().setAddress("redis://myredisserver:6379");
RedissonClient redisson = Redisson.create(config);
Distributed lock document address
https://github.com/redisson/redisson/wiki/8.-%E5%88%86%E5%B8%83%E5%BC%8F%E9%94%81%E5%92%8C%E5%90%8C%E6%AD%A5%E5%99%A8
可重入锁(Reentrant Lock)
There is no need to deal with power outages or program issues causing lock failures
RLock lock = redisson.getLock("anyLock");
// 最常见的使用方法
lock.lock();//阻塞式等待,默认30s释放,There is no need to deal with power outages or program issues causing lock failures
// 加锁以后10秒钟自动解锁
// 无需调用unlock方法手动解锁
lock.lock(10, TimeUnit.SECONDS);
// 尝试加锁,最多等待100秒,上锁以后10秒自动解锁
boolean res = lock.tryLock(100, 10, TimeUnit.SECONDS);
if (res) {
try {
...
} finally {
lock.unlock();
}
}
公平锁(Fair Lock)
FIFOAlgorithm execution locks,Queue in turn for a lock
联锁(MultiLock)
红锁(RedLock)
读写锁(ReadWriteLock)
Read locks for read business,Write business use write lock,2used together.
The read-read business is a shared lock
The rest of the business is exclusive lock(阻塞等待)
信号量(Semaphore)
Available services such as service current limit
可过期性信号量(PermitExpirableSemaphore)
闭锁(CountDownLatch)
springCache开发
边栏推荐
猜你喜欢

When does MySQL use table locks and when does it use row locks?

DNS domain name resolution services

IDEA 中CheckStyle安装及使用

Boot process and service control

C# 使用RestSharp 实现Get,Post 请求(2)

Go uses freecache for caching

云服务器零基础部署网站(保姆级教程)

What new materials are used in the large aircraft C919?

uniapp中canvas与v-if更“配”

2020年度总结——品曾经,明得失,展未来
随机推荐
预测人们对你的第一印象,“AI颜狗”的诞生
k8s 部署mysql8(PV和PVC 版本)
Keil编译大小和存储说明
Go 使用mencached缓存
LSF提交作业命令--bsub
A magical no main method of code
No, the Log4j vulnerability hasn't been fully fixed yet?
Boot process and service control
goto语句
Develop common tool software
MySQL master-slave replication configuration construction, one step in place
Upload file -- file type, picture type, document type, video type, compressed package type
BGP:边界网关路由协议 无类别的路径矢量EGP协议
DNS domain name resolution services
Go uses the mencached cache
Map file analysis in Keil software
MySql详解基础
02 多线程与高并发 - synchronized 解析
go : 使用gorm创建数据库记录
如何实时计算日累计逐单资金流