/** {@inheritDoc} */ @Override public void run() { try { while (true) { CloseablePhantomRef reference = (CloseablePhantomRef) mReferenceQueue.remove(); LOG.debug("Closing enqueued PhantomReference {}.", reference); if (mReferences.remove(reference)) { reference.clear(); // allows referent to be claimed by the GC. reference.close(); } else { // This should not happen LOG.error("Enqueued PhantomReference {} is not registered to this reaper.", reference); } } } catch (InterruptedException e) { // If this thread is interrupted, then die. This happens normally when // AutoReferenceCountedReaper#close is called. // Restore the interrupted status Thread.currentThread().interrupt(); } } }