< prev index next >

src/java.base/share/classes/jdk/internal/ref/CleanerImpl.java

Print this page

        

@@ -155,10 +155,30 @@
             }
         }
     }
 
     /**
+     * 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<Object> {
         private final Runnable action;
 
< prev index next >