void clearKeyReferenceQueue() { while (keyReferenceQueue.poll() != null) {} }
/** * Initialise this subclass during construction, cloning or deserialization. */ protected void init() { queue = new ReferenceQueue(); }
/** * Returns the next available reference from the queue, removing it in the * process. Waits indefinitely for a reference to become available. * * @throws InterruptedException if the blocking call was interrupted */ public Reference<? extends T> remove() throws InterruptedException { return remove(0L); }
<T> void clearReferenceQueue(ReferenceQueue<T> referenceQueue) { while (referenceQueue.poll() != null) {} }
/** * Sets table to new HashEntry array. * Call only while holding lock or in constructor. */ void setTable(HashEntry<K, V>[] newTable) { threshold = (int) ( newTable.length * loadFactor ); table = newTable; refQueue = new ReferenceQueue<Object>(); }
/** Loops continuously, pulling references off the queue and cleaning them up. */ @SuppressWarnings("InfiniteLoopStatement") @Override public void run() { while (true) { try { if (!cleanUp(queue.remove())) { break; } } catch (InterruptedException e) { // ignore } } }
void clearValueReferenceQueue() { while (valueReferenceQueue.poll() != null) {} }
/** * Sets table to new HashEntry array. * Call only while holding lock or in constructor. */ void setTable(HashEntry<K,V>[] newTable) { threshold = (int)(newTable.length * loadFactor); table = newTable; refQueue = new ReferenceQueue<Object>(); }
@Override public void run() { try { while (true) { Reference<? extends Buffer> toclean = BufferUtils.removeCollected.remove(); BufferUtils.trackedBuffers.remove(toclean); } } catch (InterruptedException e) { e.printStackTrace(); } } }
void clearKeyReferenceQueue() { while (keyReferenceQueue.poll() != null) {} }
/** * Initialise this subclass during construction, cloning or deserialization. */ protected void init() { queue = new ReferenceQueue(); }
/** Loops continuously, pulling references off the queue and cleaning them up. */ @SuppressWarnings("InfiniteLoopStatement") @Override public void run() { while (true) { try { if (!cleanUp(queue.remove())) { break; } } catch (InterruptedException e) { // ignore } } }
void clearValueReferenceQueue() { while (valueReferenceQueue.poll() != null) {} }
/** * Create reference store */ public ItemReferences() { queue = new ReferenceQueue<>(); items = new ConcurrentHashMap<>(); }
/** Loops continuously, pulling references off the queue and cleaning them up. */ @SuppressWarnings("InfiniteLoopStatement") @Override public void run() { while (true) { try { if (!cleanUp(queue.remove())) { break; } } catch (InterruptedException e) { // ignore } } }
<T> void clearReferenceQueue(ReferenceQueue<T> referenceQueue) { while (referenceQueue.poll() != null) {} }
/** * Creates a FirstLevelCache with a desired initial capacity. * * @param capacity - the initial capacity */ private FirstLevelCache(int capacity) { delegate = new ConcurrentHashMap<>(capacity); queue = new ReferenceQueue<>(); }
@Override public void run() { while (alive) { try { BufferReference ref = (BufferReference) garbageCollectedBuffers.remove(); //blocks ref.clear(); //this cannot race with a release() call because an object is either reachable or not, //release() can only happen before its GC'ed, and enqueue can only happen after. //if the ref was enqueued it must then not have been released BufferMetadata metadata = buffersInFlight.remove(ref); if (metadata == null) { //it can happen rarely that the buffer was release()ed properly (so no metadata) and yet //the reference object to it remains reachable for a short period of time after release() //and hence gets enqueued. this is because we keep refs in a ConcurrentHashMap which cleans //up keys lazily. continue; } availableMemory.addAndGet(metadata.sizeBytes); log.error("Reclaimed buffer of size {} and identity {} that was not properly release()ed. This is a bug.", metadata.sizeBytes, ref.hashCode); } catch (InterruptedException e) { log.debug("interrupted", e); //ignore, we're a daemon thread } } log.info("GC listener shutting down"); } }
private void removeWeaklyReachableReferences() { // WeakReferences are enqueued as soon as the object to which they point to becomes weakly // reachable. This is before finalization or garbage collection has actually happened. KeyedWeakReference ref; while ((ref = (KeyedWeakReference) queue.poll()) != null) { retainedKeys.remove(ref.key); } } }
/** Constructs a new queue. */ public FinalizableReferenceQueue() { // We could start the finalizer lazily, but I'd rather it blow up early. queue = new ReferenceQueue<>(); frqRef = new PhantomReference<Object>(this, queue); boolean threadStarted = false; try { startFinalizer.invoke(null, FinalizableReference.class, queue, frqRef); threadStarted = true; } catch (IllegalAccessException impossible) { throw new AssertionError(impossible); // startFinalizer() is public } catch (Throwable t) { logger.log( Level.INFO, "Failed to start reference finalizer thread." + " Reference cleanup will only occur when new references are created.", t); } this.threadStarted = threadStarted; }