public SoftReference<BufferRecycler> wrapAndTrack(BufferRecycler br) { SoftReference<BufferRecycler> newRef; newRef = new SoftReference<BufferRecycler>(br, _refQueue); // also retain softRef to br in a set to be able to release it on shutdown _trackedRecyclers.put(newRef, true); // gc may have cleared one or more SoftRefs, clean them up to avoid a memleak removeSoftRefsClearedByGc(); return newRef; }
public SoftReference<BufferRecycler> wrapAndTrack(BufferRecycler br) { SoftReference<BufferRecycler> newRef; newRef = new SoftReference<BufferRecycler>(br, _refQueue); // also retain softRef to br in a set to be able to release it on shutdown _trackedRecyclers.put(newRef, true); // gc may have cleared one or more SoftRefs, clean them up to avoid a memleak removeSoftRefsClearedByGc(); return newRef; }
/** * Releases the buffers retained in ThreadLocals. To be called for instance on shutdown event of applications which make use of * an environment like an appserver which stays alive and uses a thread pool that causes ThreadLocals created by the * application to survive much longer than the application itself. * It will clear all bufRecyclers from the SoftRefs and release all SoftRefs itself from our set. */ public int releaseBuffers() { synchronized (RELEASE_LOCK) { int count = 0; // does this need to be in sync block too? Looping over Map definitely has to but... removeSoftRefsClearedByGc(); // make sure the refQueue is empty for (SoftReference<BufferRecycler> ref : _trackedRecyclers.keySet()) { ref.clear(); // possibly already cleared by gc, nothing happens in that case ++count; } _trackedRecyclers.clear(); //release cleared SoftRefs return count; } }
/** * Releases the buffers retained in ThreadLocals. To be called for instance on shutdown event of applications which make use of * an environment like an appserver which stays alive and uses a thread pool that causes ThreadLocals created by the * application to survive much longer than the application itself. * It will clear all bufRecyclers from the SoftRefs and release all SoftRefs itself from our set. */ public int releaseBuffers() { synchronized (RELEASE_LOCK) { int count = 0; // does this need to be in sync block too? Looping over Map definitely has to but... removeSoftRefsClearedByGc(); // make sure the refQueue is empty for (SoftReference<BufferRecycler> ref : _trackedRecyclers.keySet()) { ref.clear(); // possibly already cleared by gc, nothing happens in that case ++count; } _trackedRecyclers.clear(); //release cleared SoftRefs return count; } }
public SoftReference<BufferRecycler> wrapAndTrack(BufferRecycler br) { SoftReference<BufferRecycler> newRef; newRef = new SoftReference<BufferRecycler>(br, _refQueue); // also retain softRef to br in a set to be able to release it on shutdown _trackedRecyclers.put(newRef, true); // gc may have cleared one or more SoftRefs, clean them up to avoid a memleak removeSoftRefsClearedByGc(); return newRef; }
/** * Releases the buffers retained in ThreadLocals. To be called for instance on shutdown event of applications which make use of * an environment like an appserver which stays alive and uses a thread pool that causes ThreadLocals created by the * application to survive much longer than the application itself. * It will clear all bufRecyclers from the SoftRefs and release all SoftRefs itself from our set. */ public int releaseBuffers() { synchronized (RELEASE_LOCK) { int count = 0; // does this need to be in sync block too? Looping over Map definitely has to but... removeSoftRefsClearedByGc(); // make sure the refQueue is empty for (SoftReference<BufferRecycler> ref : _trackedRecyclers.keySet()) { ref.clear(); // possibly already cleared by gc, nothing happens in that case ++count; } _trackedRecyclers.clear(); //release cleared SoftRefs return count; } }