From 0361d7684c19de7c9346b9545d3d9a429a472c80 Mon Sep 17 00:00:00 2001 From: HaoRan <418836876@qq.com> Date: Sun, 4 Apr 2021 21:46:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=BC=93=E5=AD=98=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E7=9A=84=E5=91=BD=E4=B8=AD=E8=AE=A1=E6=95=B0=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/hutool/cache/impl/AbstractCache.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/hutool-cache/src/main/java/cn/hutool/cache/impl/AbstractCache.java b/hutool-cache/src/main/java/cn/hutool/cache/impl/AbstractCache.java index e860f5375..62783db6e 100644 --- a/hutool-cache/src/main/java/cn/hutool/cache/impl/AbstractCache.java +++ b/hutool-cache/src/main/java/cn/hutool/cache/impl/AbstractCache.java @@ -9,7 +9,7 @@ import java.util.Iterator; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.atomic.LongAdder; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.StampedLock; @@ -58,11 +58,11 @@ public abstract class AbstractCache implements Cache { /** * 命中数,即命中缓存计数 */ - protected AtomicLong hitCount = new AtomicLong(); + protected LongAdder hitCount = new LongAdder(); /** * 丢失数,即未命中缓存计数 */ - protected AtomicLong missCount = new AtomicLong(); + protected LongAdder missCount = new LongAdder(); /** * 缓存监听 @@ -133,14 +133,14 @@ public abstract class AbstractCache implements Cache { * @return 命中数 */ public long getHitCount() { - return hitCount.get(); + return hitCount.sum(); } /** * @return 丢失数 */ public long getMissCount() { - return missCount.get(); + return missCount.sum(); } @Override @@ -188,10 +188,10 @@ public abstract class AbstractCache implements Cache { // 未命中 if (null == co) { - missCount.getAndIncrement(); + missCount.increment(); return null; } else if (false == co.isExpired()) { - hitCount.getAndIncrement(); + hitCount.increment(); return co.get(isUpdateLastAccess); } @@ -368,7 +368,7 @@ public abstract class AbstractCache implements Cache { final CacheObj co = cacheMap.remove(key); if (withMissCount) { // 在丢失计数有效的情况下,移除一般为get时的超时操作,此处应该丢失数+1 - this.missCount.getAndIncrement(); + this.missCount.increment(); } return co; }