当前位置:网站首页>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开发
边栏推荐
猜你喜欢

C language custom types, rounding

Is it possible to use the same port for UDP and TCP?

Go 结合Gin导出Mysql数据到Excel表格

Go 使用mencached缓存

How does Redis prevent oversold and inventory deduction operations?

C# 获取系统已安装的.NET版本

golang : Zap日志整合

selenium模块

Architectural Design Guide How to Become an Architect

No, the Log4j vulnerability hasn't been fully fixed yet?
随机推荐
什么是微服务?
The newcomer deleted data by mistake, and the team leader skillfully used MySQL master-slave replication to delay the recovery of losses
Derivative Operations on Vectors and Derivative Operations on Vector Cross and Dot Products
Oracle查看表空间使用率及爆满解决方案
Go uses freecache for caching
[硬核干货]由0到1,突破信息系统项目管理师(呕心沥血经验之谈)!!!
window.open()的用法,js打开新窗体
Boot process and service control
分布式锁开发
Electron之初出茅庐——搭建环境并运行第一个程序
General Lei's personal blog to see
go : go-redis 基础操作
从 Google 离职,前Go 语言负责人跳槽小公司
Is it possible to use the same port for UDP and TCP?
2020 数学建模之旅
go : 使用gorm查询记录
interface
2020年度总结——品曾经,明得失,展未来
01 多线程与高并发 - 基础概念
【COCI 2020/2021 Round #2 D】Magneti(DP)