当前位置:网站首页>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开发
边栏推荐
- Electron之初出茅庐——搭建环境并运行第一个程序
- goto语句
- 专访蚂蚁:这群技术排头兵,如何做好底层开发这件事?| 卓越技术团队访谈录
- From catching up to surpassing, domestic software shows its talents
- What new materials are used in the large aircraft C919?
- selenium module
- go : go-redis 基础操作
- Is it possible to use the same port for UDP and TCP?
- 理解和熟悉递归中的尝试
- window.open()的用法,js打开新窗体
猜你喜欢

2020 ACM | MoFlow: An Invertible Flow Model for Generating Molecular Graphs

物联网网关该怎么选

C语言自定义类型详解

Ali Ermian: How many cluster solutions does Redis have?I answered 4

便携小风扇PD取电芯片

How to calculate the daily cumulative capital flow one by one in real time

New breakthrough in artificial muscle smart materials

限塑令下的新材料——聚乳酸(PLA)

首届人工智能安全大赛正式启动

如何实时计算日累计逐单资金流
随机推荐
理解和熟悉递归中的尝试
When does MySQL use table locks and when does it use row locks?
Derivative Operations on Vectors and Derivative Operations on Vector Cross and Dot Products
Go 使用 freecache 缓存
Upload file -- file type, picture type, document type, video type, compressed package type
Calculate the inverse source of the matrix (using the adjoint matrix, a 3x3 matrix)
MySQL题外篇【ORM思想解析】
The usage of window.open(), js opens a new form
Go: go - redis based operation
ArrayList
go : create database records using gorm
go : delete database data using grom
The calculation and source code of the straight line intersecting the space plane
Boot process and service control
export , export default,import完整用法
Basic usage of tree arrays
golang : Zap log integration
2020 ACM | MoFlow: An Invertible Flow Model for Generating Molecular Graphs
Architectural Design Guide How to Become an Architect
Go 结合Gin导出Mysql数据到Excel表格