From bc12b4c3b1b3ef89669ea2201c75651eb4987c90 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Fri, 23 May 2025 11:13:04 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E5=8F=AF=E4=BB=A5=E5=9C=A8=E9=AB=98=E5=B9=B6?= =?UTF-8?q?=E5=8F=91=E5=9C=BA=E6=99=AF=E4=B8=8B=E9=98=B2=E6=AD=A2=E8=A2=AB?= =?UTF-8?q?=E5=87=BB=E7=A9=BF=E7=9A=84Mybaties=E4=BA=8C=E7=BA=A7=E7=BC=93?= =?UTF-8?q?=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1421727635046400]增加一个可以在高并发场景下防止被击穿的Mybaties二级缓存 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1421727635046400 --- .../framework/dao/cache/NeatLogicConcurrentSafeCache.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/neatlogic/framework/dao/cache/NeatLogicConcurrentSafeCache.java b/src/main/java/neatlogic/framework/dao/cache/NeatLogicConcurrentSafeCache.java index 3784cca93..32abe16a9 100644 --- a/src/main/java/neatlogic/framework/dao/cache/NeatLogicConcurrentSafeCache.java +++ b/src/main/java/neatlogic/framework/dao/cache/NeatLogicConcurrentSafeCache.java @@ -103,7 +103,7 @@ public class NeatLogicConcurrentSafeCache implements Cache { if (CollectionUtils.isNotEmpty(keys)) { for (Object key : keys) { ReentrantLock lock = LOCAL_LOCK_MAP.remove(generateLockKey(getId(), key)); - if (lock != null && lock.isLocked()) { + if (lock != null && lock.isLocked() && lock.isHeldByCurrentThread()) { lock.unlock(); } } @@ -135,7 +135,7 @@ public class NeatLogicConcurrentSafeCache implements Cache { } cachedElement = getCache().get(key); if (cachedElement != null) { - if (lock.isLocked()) { + if (lock.isLocked() && lock.isHeldByCurrentThread()) { lock.unlock(); } return cachedElement.getObjectValue(); @@ -158,7 +158,7 @@ public class NeatLogicConcurrentSafeCache implements Cache { public void putObject(Object key, Object value) { getCache().put(new Element(key, value)); ReentrantLock lock = LOCAL_LOCK_MAP.remove(generateLockKey(getId(), key)); - if (lock != null) { + if (lock != null && lock.isLocked() && lock.isHeldByCurrentThread()) { lock.unlock(); } } @@ -171,7 +171,7 @@ public class NeatLogicConcurrentSafeCache implements Cache { Object obj = getObject(key); getCache().remove(key); ReentrantLock lock = LOCAL_LOCK_MAP.remove(generateLockKey(getId(), key)); - if (lock != null) { + if (lock != null && lock.isLocked() && lock.isHeldByCurrentThread()) { lock.unlock(); } return obj; -- Gitee