--- old/src/java.base/share/classes/jdk/internal/ref/CleanerImpl.java 2016-03-23 13:44:04.742016498 +0100 +++ new/src/java.base/share/classes/jdk/internal/ref/CleanerImpl.java 2016-03-23 13:44:04.589015753 +0100 @@ -157,6 +157,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 {