当前位置:网站首页>Redisson distributed lock unlocking exception
Redisson distributed lock unlocking exception
2022-07-08 01:51:00 【Know what you know】
Problem phenomenon
In program redission perform unlock() An error is as follows :
java.lang.IllegalMonitorStateException: attempt to unlock lock, not locked by current thread by node id:
According to the error information : Try unlocking , Instead of the current thread by node ID lock
Problem recurrence
// Get lock object
RLock lock = redissonClient.getLock(key);
try{
// Get the lock
boolean tryLock = lock.tryLock(5, TimeUnit.SECONDS);
if (!tryLock) {
// Throw business exception
}
}catch(){
// Capture exception
}finally{
// Unlock
lock.unlock();
}The screening process
Code above , Whether or not a thread acquires a lock , It is necessary to implement the unlocking method , When a thread does not acquire a lock , perform unlock() Will report java.lang.IllegalMonitorStateException: attempt to unlock lock, not locked by current thread by node id: error
Solution
1、 Increase judgment when unlocking
// Determine the to unlock key Whether it has been locked ; Determine the to unlock key Whether it is held by the current thread
if (lock.isLocked() && lock.isHeldByCurrentThread()) {
lock.unlock();
}2、 Optimize the code
In execution unlock() Make sure that the thread has acquired the lock
// Get lock object
RLock lock = redissonClient.getLock(key);
boolean tryLock;
try {
tryLock = lock.tryLock(5, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new Exception(" Failed to acquire a distributed lock , Please try again later ");
}
if (!tryLock) {
throw new Exception(" Please try again later ");
}
try{
// Throw business exception
}catch(){
// Capture exception
}finally{
// Unlock
lock.unlock();
}边栏推荐
- 什么样的MES系统才是好系统
- Break algorithm --- map
- Introduction to grpc for cloud native application development
- COMSOL----微阻梁模型的搭建---最终的温度分布和变形情况---材料的添加
- Version 2.0 of tapdata, the open source live data platform, has been released
- nacos-微服务网关Gateway组件 +Swagger2接口生成
- Optimization of ecological | Lake Warehouse Integration: gbase 8A MPP + xeos
- Matlab r2021b installing libsvm
- php 获取音频时长等信息
- Application of slip ring in direct drive motor rotor
猜你喜欢

用户之声 | 对于GBase 8a数据库学习的感悟

Capability contribution three solutions of gbase were selected into the "financial information innovation ecological laboratory - financial information innovation solutions (the first batch)"

ArrayList源码深度剖析,从最基本的扩容原理,到魔幻的迭代器和fast-fail机制,你想要的这都有!!!

The foreach map in JS cannot jump out of the loop problem and whether foreach will modify the original array

从cmath文件看名字是怎样被添加到命名空间std中的
![[target tracking] |atom](/img/33/529b483a0a848e0e4263ba24462d5c.png)
[target tracking] |atom

如何让导电滑环信号更好

About snake equation (3)

Write a pure handwritten QT Hello World

进程和线程的退出
随机推荐
Deep learning website
PB9.0 insert OLE control error repair tool
第七章 行为级建模
nmap工具介绍及常用命令
The body has a mysterious margin of 8px
The numerical value of the number of figures thought of by the real-time update of the ranking list
【错误】加载h5权重出错AttributeError: ‘str‘ object has no attribute ‘decode‘
滑环在直驱电机转子的应用领域
Anaconda3 download address Tsinghua University open source software mirror station
MATLAB R2021b 安装libsvm
Matlab r2021b installing libsvm
系统测试的类型有哪些,我给你介绍
Nacos microservice gateway component +swagger2 interface generation
The foreach map in JS cannot jump out of the loop problem and whether foreach will modify the original array
[SolidWorks] modify the drawing format
cv2读取视频-并保存图像或视频
nacos-微服务网关Gateway组件 +Swagger2接口生成
子矩阵的和
Kafka connect synchronizes Kafka data to MySQL
Android 创建的sqlite3数据存放位置