mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-16 02:15:51 +00:00
1 file changed
+4
-4
@@ -8,7 +8,7 @@ import java.util.List;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -62,7 +62,7 @@ public class LazyCache<K, V> {
|
|||||||
private ConcurrentMap<K, Cache<K, V>> cacheMap;
|
private ConcurrentMap<K, Cache<K, V>> cacheMap;
|
||||||
private BiConsumer<List<Cache<K, V>>, RemovalCause> removeListener = (removes, removalCause) -> {
|
private BiConsumer<List<Cache<K, V>>, 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<List<Cache<K, V>>, RemovalCause> removeListener) {
|
public LazyCache(int maximumSize, long expireAfterAccessMillis, long expireCheckIntervalMillis, BiConsumer<List<Cache<K, V>>, RemovalCause> removeListener) {
|
||||||
AssertionUtils.ge1(maximumSize);
|
AssertionUtils.ge1(maximumSize);
|
||||||
@@ -157,7 +157,7 @@ public class LazyCache<K, V> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void checkMaximumSize() {
|
private void checkMaximumSize() {
|
||||||
if (rwLock.writeLock().tryLock()) { // 获取写锁
|
if (lock.tryLock()) { // 获取写锁
|
||||||
try {
|
try {
|
||||||
if (cacheMap.size() > backPressureSize) {
|
if (cacheMap.size() > backPressureSize) {
|
||||||
var removeList = cacheMap.values()
|
var removeList = cacheMap.values()
|
||||||
@@ -168,7 +168,7 @@ public class LazyCache<K, V> {
|
|||||||
removeForCause(removeList, RemovalCause.SIZE);
|
removeForCause(removeList, RemovalCause.SIZE);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
rwLock.writeLock().unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user