From 62474f6f2269b4305e840070cff26f50842ef936 Mon Sep 17 00:00:00 2001 From: "blake.qiu" Date: Mon, 14 Aug 2023 14:52:07 +0800 Subject: [PATCH] feat(#10963): In CacheItem, it's better to use the private and final keywords to modify the member variable rwLock. --- .../com/alibaba/nacos/config/server/model/CacheItem.java | 6 +----- .../nacos/config/server/service/ConfigCacheService.java | 8 ++++---- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/config/src/main/java/com/alibaba/nacos/config/server/model/CacheItem.java b/config/src/main/java/com/alibaba/nacos/config/server/model/CacheItem.java index 126cc59d5b8..3721a8b34ca 100644 --- a/config/src/main/java/com/alibaba/nacos/config/server/model/CacheItem.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/model/CacheItem.java @@ -60,7 +60,7 @@ public class CacheItem { */ private volatile Map configCacheTags = null; - public SimpleReadWriteLock rwLock = new SimpleReadWriteLock(); + private final SimpleReadWriteLock rwLock = new SimpleReadWriteLock(); public CacheItem(String groupKey, String encryptedDataKey) { this.groupKey = StringPool.get(groupKey); @@ -104,10 +104,6 @@ public SimpleReadWriteLock getRwLock() { return rwLock; } - public void setRwLock(SimpleReadWriteLock rwLock) { - this.rwLock = rwLock; - } - public String getType() { return type; } diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/ConfigCacheService.java b/config/src/main/java/com/alibaba/nacos/config/server/service/ConfigCacheService.java index 171a3b1a4fe..af10afee1a2 100644 --- a/config/src/main/java/com/alibaba/nacos/config/server/service/ConfigCacheService.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/service/ConfigCacheService.java @@ -831,7 +831,7 @@ public static boolean isUptodate(String groupKey, String md5, String ip, String */ public static int tryReadLock(String groupKey) { CacheItem groupItem = CACHE.get(groupKey); - int result = (null == groupItem) ? 0 : (groupItem.rwLock.tryReadLock() ? 1 : -1); + int result = (null == groupItem) ? 0 : (groupItem.getRwLock().tryReadLock() ? 1 : -1); if (result < 0) { DEFAULT_LOG.warn("[read-lock] failed, {}, {}", result, groupKey); } @@ -846,7 +846,7 @@ public static int tryReadLock(String groupKey) { public static void releaseReadLock(String groupKey) { CacheItem item = CACHE.get(groupKey); if (null != item) { - item.rwLock.releaseReadLock(); + item.getRwLock().releaseReadLock(); } } @@ -859,7 +859,7 @@ public static void releaseReadLock(String groupKey) { */ static int tryWriteLock(String groupKey) { CacheItem groupItem = CACHE.get(groupKey); - int result = (null == groupItem) ? 0 : (groupItem.rwLock.tryWriteLock() ? 1 : -1); + int result = (null == groupItem) ? 0 : (groupItem.getRwLock().tryWriteLock() ? 1 : -1); if (result < 0) { DEFAULT_LOG.warn("[write-lock] failed, {}, {}", result, groupKey); } @@ -869,7 +869,7 @@ static int tryWriteLock(String groupKey) { static void releaseWriteLock(String groupKey) { CacheItem groupItem = CACHE.get(groupKey); if (null != groupItem) { - groupItem.rwLock.releaseWriteLock(); + groupItem.getRwLock().releaseWriteLock(); } }