SafetyNetCloseableRegistry extends
		AbstractCloseableRegistry<WrappingProxyCloseable<? extends Closeable>,
				SafetyNetCloseableRegistry.PhantomDelegatingCloseableRef> { @Override public void close() throws IOException { try { super.close(); } finally { synchronized (REAPER_THREAD_LOCK) { --GLOBAL_SAFETY_NET_REGISTRY_COUNT; if (0 == GLOBAL_SAFETY_NET_REGISTRY_COUNT) { REAPER_THREAD.interrupt(); REAPER_THREAD = null; } } } } SafetyNetCloseableRegistry(); @Override void close();  }
@Test public void testSafetyNetClose() throws Exception { setup(20); startThreads(); joinThreads(); for (int i = 0; i < 5 && unclosedCounter.get() > 0; ++i) { System.gc(); Thread.sleep(50); } Assert.assertEquals(0, unclosedCounter.get()); closeableRegistry.close(); }