< prev index next >
src/java.base/share/classes/jdk/internal/ref/CleanerImpl.java
Print this page
*** 74,84 ****
/**
* Called to get the CleanerImpl for a Cleaner.
* @param cleaner the cleaner
* @return the corresponding CleanerImpl
*/
! static CleanerImpl getCleanerImpl(Cleaner cleaner) {
return cleanerImplAccess.apply(cleaner);
}
/**
* Constructor for CleanerImpl.
--- 74,84 ----
/**
* Called to get the CleanerImpl for a Cleaner.
* @param cleaner the cleaner
* @return the corresponding CleanerImpl
*/
! public static CleanerImpl getCleanerImpl(Cleaner cleaner) {
return cleanerImplAccess.apply(cleaner);
}
/**
* Constructor for CleanerImpl.
*** 145,163 ****
// due to a race with clear/clean
Cleanable ref = (Cleanable) queue.remove(60 * 1000L);
if (ref != null) {
ref.clean();
}
- } catch (InterruptedException i) {
- continue; // ignore the interruption
} catch (Throwable e) {
// ignore exceptions from the cleanup action
}
}
}
/**
* Perform cleaning on an unreachable PhantomReference.
*/
public static final class PhantomCleanableRef extends PhantomCleanable<Object> {
private final Runnable action;
--- 145,182 ----
// due to a race with clear/clean
Cleanable ref = (Cleanable) queue.remove(60 * 1000L);
if (ref != null) {
ref.clean();
}
} 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<Object> {
private final Runnable action;
< prev index next >