--- old/src/java.base/share/classes/jdk/internal/ref/CleanerImpl.java 2016-02-07 17:26:32.704981491 +0100 +++ new/src/java.base/share/classes/jdk/internal/ref/CleanerImpl.java 2016-02-07 17:26:32.602983214 +0100 @@ -76,7 +76,7 @@ * @param cleaner the cleaner * @return the corresponding CleanerImpl */ - static CleanerImpl getCleanerImpl(Cleaner cleaner) { + public static CleanerImpl getCleanerImpl(Cleaner cleaner) { return cleanerImplAccess.apply(cleaner); } @@ -147,15 +147,34 @@ if (ref != null) { ref.clean(); } - } catch (InterruptedException i) { - continue; // ignore the interruption } catch (Throwable e) { // ignore exceptions from the cleanup action + // (including interruption of cleanup thread) } } } /** + * Processes all Cleanable(s) that have been waiting in the queue. + * + * @return {@code true} if any Cleanable was found in the queue and + * was processed or {@code false} if the queue was empty. + */ + public boolean drainQueue() { + boolean cleaned = false; + Cleanable ref; + while ((ref = (Cleanable) queue.poll()) != null) { + try { + ref.clean(); + } catch (Throwable t) { + // ignore exceptions from the cleanup action + } + cleaned = true; + } + return cleaned; + } + + /** * Perform cleaning on an unreachable PhantomReference. */ public static final class PhantomCleanableRef extends PhantomCleanable {