@Test(timeout = 10000) public void testWatch() throws Exception { final CountDownLatch latch = new CountDownLatch(1); final Thread t = new Thread() { @Override public void run() { for (;;) { try { Thread.sleep(1000); } catch (InterruptedException ignore) { break; } } } }; final Runnable task = new Runnable() { @Override public void run() { if (!t.isAlive()) { latch.countDown(); } } }; try { ThreadDeathWatcher.watch(t, task); fail("must reject to watch a non-alive thread."); } catch (IllegalArgumentException e) { } t.start(); ThreadDeathWatcher.watch(t, task); assertThat(latch.await(750, TimeUnit.MILLISECONDS), is(false)); t.interrupt(); latch.await(); }
public static void watch(Thread thread, Runnable task) { if (thread == null) { throw new NullPointerException("thread"); } if (task == null) { throw new NullPointerException("task"); } if (!thread.isAlive()) { throw new IllegalArgumentException("thread must be alive."); } schedule(thread, task, true); }
ThreadDeathWatcher { public static void watch(Thread thread, Runnable task) { if (thread == null) { throw new NullPointerException("thread"); } if (task == null) { throw new NullPointerException("task"); } if (!thread.isAlive()) { throw new IllegalArgumentException("thread must be alive."); } schedule(thread, task, true); } }
ThreadDeathWatcher { public static void watch(Thread thread, Runnable task) { if (thread == null) { throw new NullPointerException("thread"); } if (task == null) { throw new NullPointerException("task"); } if (!thread.isAlive()) { throw new IllegalArgumentException("thread must be alive."); } schedule(thread, task, true); } private  ThreadDeathWatcher(); }
ThreadDeathWatcher { public static void watch(Thread thread, Runnable task) { if (thread == null) { throw new NullPointerException("thread"); } if (task == null) { throw new NullPointerException("task"); } if (!thread.isAlive()) { throw new IllegalArgumentException("thread must be alive."); } schedule(thread, task, true); } private  ThreadDeathWatcher(); static void watch(Thread thread, Runnable task); static void unwatch(Thread thread, Runnable task); static boolean awaitInactivity(long timeout, TimeUnit unit); }
ThreadDeathWatcher { public static void watch(Thread thread, Runnable task) { if (thread == null) { throw new NullPointerException("thread"); } if (task == null) { throw new NullPointerException("task"); } if (!thread.isAlive()) { throw new IllegalArgumentException("thread must be alive."); } schedule(thread, task, true); } private  ThreadDeathWatcher(); static void watch(Thread thread, Runnable task); static void unwatch(Thread thread, Runnable task); static boolean awaitInactivity(long timeout, TimeUnit unit);  }