From 875a121af4a1779da54b9d1859b6ad7aa00de316 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 6 Mar 2025 10:38:46 +0800 Subject: [PATCH] =?UTF-8?q?LazyCache=20-=20=E9=94=81=E6=9C=BA=E5=88=B6?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/zfoo/scheduler/util/LazyCache.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scheduler/src/main/java/com/zfoo/scheduler/util/LazyCache.java b/scheduler/src/main/java/com/zfoo/scheduler/util/LazyCache.java index ec2e10f2..b167b5df 100644 --- a/scheduler/src/main/java/com/zfoo/scheduler/util/LazyCache.java +++ b/scheduler/src/main/java/com/zfoo/scheduler/util/LazyCache.java @@ -8,7 +8,7 @@ import java.util.List; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.atomic.AtomicLong; -import java.util.concurrent.locks.ReentrantReadWriteLock; +import java.util.concurrent.locks.ReentrantLock; import java.util.function.BiConsumer; /** @@ -62,7 +62,7 @@ public class LazyCache { private ConcurrentMap> cacheMap; private BiConsumer>, RemovalCause> removeListener = (removes, removalCause) -> { }; - private final ReentrantReadWriteLock rwLock = new ReentrantReadWriteLock(); + private final ReentrantLock lock = new ReentrantLock(); public LazyCache(int maximumSize, long expireAfterAccessMillis, long expireCheckIntervalMillis, BiConsumer>, RemovalCause> removeListener) { AssertionUtils.ge1(maximumSize); @@ -157,7 +157,7 @@ public class LazyCache { } private void checkMaximumSize() { - if (rwLock.writeLock().tryLock()) { // 获取写锁 + if (lock.tryLock()) { // 获取写锁 try { if (cacheMap.size() > backPressureSize) { var removeList = cacheMap.values() @@ -168,7 +168,7 @@ public class LazyCache { removeForCause(removeList, RemovalCause.SIZE); } } finally { - rwLock.writeLock().unlock(); + lock.unlock(); } } }