@Test public void assertThatLaunchOnlyAllowsOneInstance() { ReferenceQueue<ContextWriteSession> referenceQueue=new ReferenceQueue<ContextWriteSession>(); int t1=Thread.activeCount(); WriteSessionCleaner.launch(referenceQueue); awaitStartUp(); int t2=Thread.activeCount(); WriteSessionCleaner.launch(referenceQueue); int t3=Thread.activeCount(); assertThat(t2,greaterThan(t1)); assertThat(t3,equalTo(t2)); }
static synchronized void launch(ReferenceQueue<ContextWriteSession> referenceQueue) { if(!isActive()) { instance=new WriteSessionCleaner(referenceQueue); instance.start(); } }
WriteSessionCleaner { static synchronized void launch(ReferenceQueue<ContextWriteSession> referenceQueue) { if(!isActive()) { instance=new WriteSessionCleaner(referenceQueue); instance.start(); } } }
WriteSessionCleaner { static synchronized void launch(ReferenceQueue<ContextWriteSession> referenceQueue) { if(!isActive()) { instance=new WriteSessionCleaner(referenceQueue); instance.start(); } } private  WriteSessionCleaner(final ReferenceQueue<ContextWriteSession> referenceQueue); }
WriteSessionCleaner { static synchronized void launch(ReferenceQueue<ContextWriteSession> referenceQueue) { if(!isActive()) { instance=new WriteSessionCleaner(referenceQueue); instance.start(); } } private  WriteSessionCleaner(final ReferenceQueue<ContextWriteSession> referenceQueue);  }
WriteSessionCleaner { static synchronized void launch(ReferenceQueue<ContextWriteSession> referenceQueue) { if(!isActive()) { instance=new WriteSessionCleaner(referenceQueue); instance.start(); } } private  WriteSessionCleaner(final ReferenceQueue<ContextWriteSession> referenceQueue);   }