Search in sources :

Example 1 with Cleaner

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();
    }
}
Also used : Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) Cleanable(java.lang.ref.Cleaner.Cleanable) Cleaner(java.lang.ref.Cleaner)

Aggregations

Cleaner (java.lang.ref.Cleaner)1 Cleanable (java.lang.ref.Cleaner.Cleanable)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1