--- old/src/java.base/share/classes/jdk/internal/ref/CleanerImpl.java 2016-03-19 00:16:20.531440348 +0100 +++ new/src/java.base/share/classes/jdk/internal/ref/CleanerImpl.java 2016-03-19 00:16:20.469441383 +0100 @@ -156,6 +156,26 @@ } /** + * Processes next Cleanable that has been waiting in the queue. + * + * @return {@code true} if a Cleanable was found in the queue and + * was processed or {@code false} if the queue was empty. + */ + public boolean cleanNextEnqueued() { + Cleanable ref = (Cleanable) queue.poll(); + if (ref != null) { + try { + ref.clean(); + } catch (Throwable t) { + // ignore exceptions from the cleanup action + } + return true; + } else { + return false; + } + } + + /** * Perform cleaning on an unreachable PhantomReference. */ public static final class PhantomCleanableRef extends PhantomCleanable {