Remove WeakOrderedQueue from WeakHashMap when FastThreadLocal value was removed if possible.
Motivation: We should remove the WeakOrderedQueue from the WeakHashMap directly if possible and only depend on the semantics of the WeakHashMap if there is no other way for us to cleanup it. Modifications: Override onRemoval(...) to remove the WeakOrderedQueue if possible. Result: Less overhead and quicker collection of WeakOrderedQueue for some cases.
This commit is contained in:
parent
79ed1c6871
commit
640a22df9e
@ -114,6 +114,16 @@ public abstract class Recycler<T> {
|
|||||||
return new Stack<T>(Recycler.this, Thread.currentThread(), maxCapacityPerThread, maxSharedCapacityFactor,
|
return new Stack<T>(Recycler.this, Thread.currentThread(), maxCapacityPerThread, maxSharedCapacityFactor,
|
||||||
ratioMask, maxDelayedQueuesPerThread);
|
ratioMask, maxDelayedQueuesPerThread);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onRemoval(Stack<T> value) {
|
||||||
|
// Let us remove the WeakOrderQueue from the WeakHashMap directly if its safe to remove some overhead
|
||||||
|
if (value.threadRef.get() == Thread.currentThread()) {
|
||||||
|
if (DELAYED_RECYCLED.isSet()) {
|
||||||
|
DELAYED_RECYCLED.get().remove(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
protected Recycler() {
|
protected Recycler() {
|
||||||
|
Loading…
Reference in New Issue
Block a user