use of java.lang.ref.Cleaner in project openj9 by eclipse.
the class CleanerShutdown method shutdownCleaner.
public static void shutdownCleaner() {
Cleaner commonCleaner = CleanerFactory.cleaner();
CleanerImpl commonCleanerImpl = CleanerImpl.getCleanerImpl(commonCleaner);
Cleanable ref = null;
while ((ref = (Cleanable) commonCleanerImpl.queue.poll()) != null) {
try {
ref.clean();
} catch (Throwable t) {
/* do nothing */
}
}
try {
// $NON-NLS-1$
Method phantomRemove = PhantomCleanable.class.getDeclaredMethod("remove", (Class<?>[]) null);
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
phantomRemove.setAccessible(true);
return null;
});
while (!commonCleanerImpl.phantomCleanableList.isListEmpty()) {
phantomRemove.invoke(commonCleanerImpl.phantomCleanableList, (Object[]) null);
}
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
/* should not fail */
e.printStackTrace();
}
}
Aggregations