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

BGP:边界网关路由协议 无类别的路径矢量EGP协议

从 Google 离职,前Go 语言负责人跳槽小公司

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

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

Go uses freecache for caching

From catching up to surpassing, domestic software shows its talents

MYSQL下载及安装完整教程

Go语学习笔记 - gorm使用 - 数据库配置、表新增 Web框架Gin(七)

架构设计指南 如何成为架构师

【MySQL】MySQL中如何实现分页操作
随机推荐
上传文件--文件类型大全,图片类型,文档类型,视频类型,压缩包类型
k8s 部署mysql8(PV和PVC 版本)
goto语句
redis实现分布式锁的原理
Vue2进阶篇-编程式路由导航、缓存路由组件、路由的激活与失活
C语言自定义类型详解
golang : Zap日志整合
Electron使用romote报错 : Uncaught TypeError: Cannot read property ‘BrowserWindow‘ of undefined
什么是微服务?
物联网网关该怎么选
Graphical relational database design ideas, this is too vivid
深度学习:线性回归模型
MySQL master-slave replication configuration construction, one step in place
千万级数据量的表,怎样最快速度查询?
Handler消息机制-Native层
Architectural Design Guide How to Become an Architect
Keil编译大小和存储说明
What happens when @Bean and @Component are used on the same class?
Keil软件中map文件解析
ETL为什么经常变成ELT甚至LET?