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
+1
View File
@@ -10,6 +10,7 @@
* 【core 】 GenericBuilder支持Map构建(pr#540@Github)
### 🐞Bug修复
* 【cache 】 修复ReentrantCache.toString方法线程不安全问题(issue#2140@Github)
-------------------------------------------------------------------------------------------------------------
# 5.7.21 (2022-02-14)
@@ -18,7 +18,7 @@ public abstract class ReentrantCache<K, V> extends AbstractCache<K, V> {
private static final long serialVersionUID = 1L;
// 一些特殊缓存,例如使用了LinkedHashMap的缓存,由于get方法也会改变Map的结构,导致无法使用读写锁
// 最优的解决方案是使用Guava的ConcurrentLinkedHashMap,此处使用简化的互斥锁
// TODO 最优的解决方案是使用Guava的ConcurrentLinkedHashMap,此处使用简化的互斥锁
protected final ReentrantLock lock = new ReentrantLock();
@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对应的对象
*