当前位置:网站首页>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开发
边栏推荐
- this与super
- 这个终端连接工具,碾压Xshell
- 2020年度总结——品曾经,明得失,展未来
- ArrayList
- Interview with Ant: How do these technology pioneers do the bottom-level development well?| Excellent technical team interview
- How to understand plucker coordinates (geometric understanding)
- 申请内存,std::transform和AVX256指令集用例和执行速度比较
- 架构设计指南 如何成为架构师
- this and super
- selenium module
猜你喜欢
随机推荐
AI可通过X光片识别种族,但没人知道为什么
上传文件--文件类型大全,图片类型,文档类型,视频类型,压缩包类型
Derivative Operations on Vectors and Derivative Operations on Vector Cross and Dot Products
The first artificial intelligence safety competition officially launched
Boot process and service control
Redis 如何实现防止超卖和库存扣减操作?
C# 获取系统已安装的.NET版本
go : 使用 grom 删除数据库数据
Handler消息机制-Native层
进制转换。。。
头条二面:MySQL中有几种常见的 SQL 错误用法?
获取controller中所有接口路径和名称
How to calculate the daily cumulative capital flow one by one in real time
Electron日常学习笔记
New breakthrough in artificial muscle smart materials
Go combines Gin to export Mysql data to Excel table
【COCI 2020/2021 Round #2 D】Magneti(DP)
k8s 部署mysql8(PV和PVC 版本)
Go uses freecache for caching
Universal js time date format conversion