This commit is contained in:
Looly 2022-02-16 13:46:43 +08:00
parent e6ac786c54
commit 87c42f5336
2 changed files with 12 additions and 1 deletions

View File

@ -10,6 +10,7 @@
* 【core 】 GenericBuilder支持Map构建pr#540@Github * 【core 】 GenericBuilder支持Map构建pr#540@Github
### 🐞Bug修复 ### 🐞Bug修复
* 【cache 】 修复ReentrantCache.toString方法线程不安全问题issue#2140@Github
------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------
# 5.7.21 (2022-02-14) # 5.7.21 (2022-02-14)

View File

@ -18,7 +18,7 @@ public abstract class ReentrantCache<K, V> extends AbstractCache<K, V> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
// 一些特殊缓存例如使用了LinkedHashMap的缓存由于get方法也会改变Map的结构导致无法使用读写锁 // 一些特殊缓存例如使用了LinkedHashMap的缓存由于get方法也会改变Map的结构导致无法使用读写锁
// 最优的解决方案是使用Guava的ConcurrentLinkedHashMap此处使用简化的互斥锁 // TODO 最优的解决方案是使用Guava的ConcurrentLinkedHashMap此处使用简化的互斥锁
protected final ReentrantLock lock = new ReentrantLock(); protected final ReentrantLock lock = new ReentrantLock();
@Override @Override
@ -115,6 +115,16 @@ public abstract class ReentrantCache<K, V> extends AbstractCache<K, V> {
} }
} }
@Override
public String toString() {
lock.lock();
try {
return super.toString();
} finally {
lock.unlock();
}
}
/** /**
* 移除key对应的对象 * 移除key对应的对象
* *