当前位置:网站首页>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();
}边栏推荐
- Introduction to natural language processing (NLP) based on transformers
- nmap工具介绍及常用命令
- I don't know. The real interest rate of Huabai installment is so high
- How mysql/mariadb generates core files
- Tapdata 的 2.0 版 ,開源的 Live Data Platform 現已發布
- powerbuilder 中使用线程的方法
- ANSI / NEMA- MW- 1000-2020 磁铁线标准。. 最新原版
- 能力贡献 GBASE三大解决方案入选“金融信创生态实验室-金融信创解决方案(第一批)”
- DataWorks值班表
- 从Starfish OS持续对SFO的通缩消耗,长远看SFO的价值
猜你喜欢

滑环使用如何固定

PB9.0 insert OLE control error repair tool

Optimization of ecological | Lake Warehouse Integration: gbase 8A MPP + xeos

Summary of log feature selection (based on Tianchi competition)

云原生应用开发之 gRPC 入门

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

COMSOL - Construction of micro resistance beam model - final temperature distribution and deformation - establishment of geometric model

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

MySQL查询为什么没走索引?这篇文章带你全面解析

第七章 行为级建模
随机推荐
cv2读取视频-并保存图像或视频
由排行榜实时更新想到的数状数值
Voice of users | winter goes and spring comes, waiting for flowers to bloom -- on gbase 8A learning comprehension
Redux usage
如何让导电滑环信号更好
node js 保持长连接
Tencent game client development interview (unity + cocos) double bombing social recruitment 6 rounds of interviews
【错误】加载h5权重出错AttributeError: ‘str‘ object has no attribute ‘decode‘
From starfish OS' continued deflationary consumption of SFO, the value of SFO in the long run
PHP to get information such as audio duration
ClickHouse原理解析与应用实践》读书笔记(8)
QT build with built-in application framework -- Hello World -- use min GW 32bit
如何制作企业招聘二维码?
Write a pure handwritten QT Hello World
Cross modal semantic association alignment retrieval - image text matching
MATLAB R2021b 安装libsvm
COMSOL----微阻梁模型的搭建---最终的温度分布和变形情况---材料的添加
qt--将程序打包--不要安装qt-可以直接运行
进程和线程的退出
图解网络:揭开TCP四次挥手背后的原理,结合男女朋友分手的例子,通俗易懂