@Test public void testShutdown() throws Exception { final ClientRunnable clientRunnable = new ClientRunnable() { @Override protected void customRun() throws InterruptedException { } }; final CountDownLatch latch1 = new CountDownLatch(1); final CountDownLatch latch2 = new CountDownLatch(1); final CountDownLatch latchShutDown = new CountDownLatch(1); new Thread(new Runnable() { public void run() { try { latch1.await(); latch2.countDown(); clientRunnable.shutdown(); latchShutDown.countDown(); } catch (InterruptedException e) { } } }).start(); latch1.countDown(); latch2.await(); Thread.sleep(10); clientRunnable.terminate(); assertTrue(latchShutDown.await(5, TimeUnit.SECONDS)); assertFalse(clientRunnable.running); }
public void shutdown() { if (terminated) { return; } synchronized (monitor) { running = false; while (!terminated) { try { monitor.wait(); } catch (InterruptedException ignored) { } } } }
ClientRunnable implements Runnable { public void shutdown() { if (terminated) { return; } synchronized (monitor) { running = false; while (!terminated) { try { monitor.wait(); } catch (InterruptedException ignored) { } } } } }
ClientRunnable implements Runnable { public void shutdown() { if (terminated) { return; } synchronized (monitor) { running = false; while (!terminated) { try { monitor.wait(); } catch (InterruptedException ignored) { } } } }  }
ClientRunnable implements Runnable { public void shutdown() { if (terminated) { return; } synchronized (monitor) { running = false; while (!terminated) { try { monitor.wait(); } catch (InterruptedException ignored) { } } } }  void run(); void shutdown(); }
ClientRunnable implements Runnable { public void shutdown() { if (terminated) { return; } synchronized (monitor) { running = false; while (!terminated) { try { monitor.wait(); } catch (InterruptedException ignored) { } } } }  void run(); void shutdown();  }