当前位置:网站首页>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();
}
边栏推荐
- 软件测试笔试题你会吗?
- COMSOL----微阻梁模型的搭建---最终的温度分布和变形情况----几何模型的建立
- Remote sensing contribution experience sharing
- Usage of hydraulic rotary joint
- 批次管控如何实现?MES系统给您答案
- 什么样的MES系统才是好系统
- SQLite3 data storage location created by Android
- Uniapp one click Copy function effect demo (finishing)
- Anaconda3 download address Tsinghua University open source software mirror station
- Codeforces Round #649 (Div. 2)——A. XXXXX
猜你喜欢
In depth analysis of ArrayList source code, from the most basic capacity expansion principle, to the magic iterator and fast fail mechanism, you have everything you want!!!
Application of slip ring in direct drive motor rotor
2022国内十大工业级三维视觉引导企业一览
qt--將程序打包--不要安裝qt-可以直接運行
Nacos microservice gateway component +swagger2 interface generation
Remote Sensing投稿經驗分享
微信小程序uniapp页面无法跳转:“navigateTo:fail can not navigateTo a tabbar page“
第七章 行为级建模
COMSOL----微阻梁模型的搭建---最终的温度分布和变形情况---材料的添加
Get familiar with XML parsing quickly
随机推荐
不算不知道,花呗分期的真实利率居然这么高
Chapter 7 behavior level modeling
液压旋转接头的使用事项
From starfish OS' continued deflationary consumption of SFO, the value of SFO in the long run
Redux使用
用户之声 | 对于GBase 8a数据库学习的感悟
Apache多个组件漏洞公开(CVE-2022-32533/CVE-2022-33980/CVE-2021-37839)
Write a pure handwritten QT Hello World
Tapdata 的 2.0 版 ,開源的 Live Data Platform 現已發布
能力贡献 GBASE三大解决方案入选“金融信创生态实验室-金融信创解决方案(第一批)”
云原生应用开发之 gRPC 入门
【目标跟踪】|DiMP: Learning Discriminative Model Prediction for Tracking
微软 AD 超基础入门
QT build with built-in application framework -- Hello World -- use min GW 32bit
uniapp一键复制功能效果demo(整理)
静态路由配置全面详解,静态路由快速入门指南
MySQL查询为什么没走索引?这篇文章带你全面解析
Summary of log feature selection (based on Tianchi competition)
从Starfish OS持续对SFO的通缩消耗,长远看SFO的价值
由排行榜实时更新想到的数状数值