提交 56936506 authored 作者: Andrei Tokar's avatar Andrei Tokar

limit the size of a non-resident queue

上级 6e9f7dab
...@@ -931,17 +931,21 @@ public class CacheLongKeyLIRS<V> { ...@@ -931,17 +931,21 @@ public class CacheLongKeyLIRS<V> {
void trimNonResidentQueue() { void trimNonResidentQueue() {
Entry<V> e; Entry<V> e;
int maxQueue2Size = nonResidentQueueSize * (mapSize - queue2Size); int maxQueue2Size = 4 * nonResidentQueueSize * (mapSize - queue2Size);
if (maxQueue2Size >= 0) { while (queue2Size > maxQueue2Size) {
while (queue2Size > maxQueue2Size) { e = queue2.queuePrev;
e = queue2.queuePrev; int hash = getHash(e.key);
WeakReference<V> reference = e.reference; remove(e.key, hash);
if (reference != null && reference.get() != null) { }
break; // stop trimming if entry holds a value maxQueue2Size >>= 2;
} while (queue2Size > maxQueue2Size) {
int hash = getHash(e.key); e = queue2.queuePrev;
remove(e.key, hash); WeakReference<V> reference = e.reference;
if (reference != null && reference.get() != null) {
break; // stop trimming if entry holds a value
} }
int hash = getHash(e.key);
remove(e.key, hash);
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论