@SuppressWarnings("javadoc") @Test public void closing_all_in_a_group() throws Exception { WorkerThreadGroup wtg1 = new WorkerThreadGroup("g1"); WorkerThreadGroup wtg2 = new WorkerThreadGroup("g2"); wtg1.add_subgroup(wtg2); WorkerThread t1 = new WorkerThread("t1"); WorkerThread t2 = new WorkerThread("t1"); WorkerThread t3 = new WorkerThread("t1"); wtg1.add_thread(t1); wtg1.add_thread(t3); wtg2.add_thread(t2); wtg2.add_thread(t3); class MyCT extends CloseableWorkerThread<TestCloseable> { public MyCT(String name, TestCloseable closeable) { super(name, closeable, false); } @Override protected void do_cycle_operation(TestCloseable closeable) throws Exception { synchronized (this) { wait(); } } } try ( TestCloseable c1 = new TestCloseable(); TestCloseable c2 = new TestCloseable(); TestCloseable c3 = new TestCloseable()){ MyCT ct1 = new MyCT("ct1", c1); MyCT ct2 = new MyCT("ct1", c2); MyCT ct3 = new MyCT("ct1", c3); wtg1.add_thread(ct1); wtg1.add_thread(ct3); wtg2.add_thread(ct2); wtg2.add_thread(ct3); assertFalse(ct1.closed()); assertFalse(ct2.closed()); assertFalse(ct3.closed()); assertEquals(0, c1.m_closed); assertEquals(0, c2.m_closed); assertEquals(0, c3.m_closed); CloseableWorkerThreadGroupOps.close_all(wtg1); assertTrue(ct1.closed()); assertTrue(ct2.closed()); assertTrue(ct3.closed()); assertEquals(1, c1.m_closed); assertEquals(1, c2.m_closed); assertEquals(1, c3.m_closed); } }
public synchronized boolean closed() { return m_closeable == null; }
CloseableWorkerThread extends WorkerThread implements Closeable { public synchronized boolean closed() { return m_closeable == null; } }
CloseableWorkerThread extends WorkerThread implements Closeable { public synchronized boolean closed() { return m_closeable == null; } CloseableWorkerThread(String name, T closeable,
			boolean close_on_abort); }
CloseableWorkerThread extends WorkerThread implements Closeable { public synchronized boolean closed() { return m_closeable == null; } CloseableWorkerThread(String name, T closeable,
			boolean close_on_abort); synchronized void add_listener(CloseableListener l); synchronized void remove_listener(CloseableListener l); @Override synchronized void close(); synchronized boolean closed(); }
CloseableWorkerThread extends WorkerThread implements Closeable { public synchronized boolean closed() { return m_closeable == null; } CloseableWorkerThread(String name, T closeable,
			boolean close_on_abort); synchronized void add_listener(CloseableListener l); synchronized void remove_listener(CloseableListener l); @Override synchronized void close(); synchronized boolean closed();  }