@Test(timeout = 5000) public void testCleanerThreadIsDaemon() throws Exception { temporaryObject = new Object(); ObjectCleaner.register(temporaryObject, new Runnable() { @Override public void run() { } }); Thread cleanerThread = null; for (Thread thread : Thread.getAllStackTraces().keySet()) { if (thread.getName().equals(ObjectCleaner.CLEANER_THREAD_NAME)) { cleanerThread = thread; break; } } assertNotNull(cleanerThread); assertTrue(cleanerThread.isDaemon()); }
public static void register(Object object, Runnable cleanupTask) { AutomaticCleanerReference reference = new AutomaticCleanerReference(object, ObjectUtil.checkNotNull(cleanupTask, "cleanupTask")); LIVE_SET.add(reference); if (CLEANER_RUNNING.compareAndSet(false, true)) { final Thread cleanupThread = new FastThreadLocalThread(CLEANER_TASK); cleanupThread.setPriority(Thread.MIN_PRIORITY); AccessController.doPrivileged(new PrivilegedAction<Void>() { @Override public Void run() { cleanupThread.setContextClassLoader(null); return null; } }); cleanupThread.setName(CLEANER_THREAD_NAME); cleanupThread.setDaemon(true); cleanupThread.start(); } }
ObjectCleaner { public static void register(Object object, Runnable cleanupTask) { AutomaticCleanerReference reference = new AutomaticCleanerReference(object, ObjectUtil.checkNotNull(cleanupTask, "cleanupTask")); LIVE_SET.add(reference); if (CLEANER_RUNNING.compareAndSet(false, true)) { final Thread cleanupThread = new FastThreadLocalThread(CLEANER_TASK); cleanupThread.setPriority(Thread.MIN_PRIORITY); AccessController.doPrivileged(new PrivilegedAction<Void>() { @Override public Void run() { cleanupThread.setContextClassLoader(null); return null; } }); cleanupThread.setName(CLEANER_THREAD_NAME); cleanupThread.setDaemon(true); cleanupThread.start(); } } }
ObjectCleaner { public static void register(Object object, Runnable cleanupTask) { AutomaticCleanerReference reference = new AutomaticCleanerReference(object, ObjectUtil.checkNotNull(cleanupTask, "cleanupTask")); LIVE_SET.add(reference); if (CLEANER_RUNNING.compareAndSet(false, true)) { final Thread cleanupThread = new FastThreadLocalThread(CLEANER_TASK); cleanupThread.setPriority(Thread.MIN_PRIORITY); AccessController.doPrivileged(new PrivilegedAction<Void>() { @Override public Void run() { cleanupThread.setContextClassLoader(null); return null; } }); cleanupThread.setName(CLEANER_THREAD_NAME); cleanupThread.setDaemon(true); cleanupThread.start(); } } private  ObjectCleaner(); }
ObjectCleaner { public static void register(Object object, Runnable cleanupTask) { AutomaticCleanerReference reference = new AutomaticCleanerReference(object, ObjectUtil.checkNotNull(cleanupTask, "cleanupTask")); LIVE_SET.add(reference); if (CLEANER_RUNNING.compareAndSet(false, true)) { final Thread cleanupThread = new FastThreadLocalThread(CLEANER_TASK); cleanupThread.setPriority(Thread.MIN_PRIORITY); AccessController.doPrivileged(new PrivilegedAction<Void>() { @Override public Void run() { cleanupThread.setContextClassLoader(null); return null; } }); cleanupThread.setName(CLEANER_THREAD_NAME); cleanupThread.setDaemon(true); cleanupThread.start(); } } private  ObjectCleaner(); static void register(Object object, Runnable cleanupTask); static int getLiveSetCount(); }
ObjectCleaner { public static void register(Object object, Runnable cleanupTask) { AutomaticCleanerReference reference = new AutomaticCleanerReference(object, ObjectUtil.checkNotNull(cleanupTask, "cleanupTask")); LIVE_SET.add(reference); if (CLEANER_RUNNING.compareAndSet(false, true)) { final Thread cleanupThread = new FastThreadLocalThread(CLEANER_TASK); cleanupThread.setPriority(Thread.MIN_PRIORITY); AccessController.doPrivileged(new PrivilegedAction<Void>() { @Override public Void run() { cleanupThread.setContextClassLoader(null); return null; } }); cleanupThread.setName(CLEANER_THREAD_NAME); cleanupThread.setDaemon(true); cleanupThread.start(); } } private  ObjectCleaner(); static void register(Object object, Runnable cleanupTask); static int getLiveSetCount();  }