@Test public void should_wait_until_woken() throws ExecutionException, InterruptedException { Waiter waiter = new Waiter(Duration.ofMillis(1000)); Future<Long> waitTime = executor.submit(new WaitForWaiter(waiter)); sleep(20); waiter.wake(); assertTrue(waitTime.get() < 100L, "Waited: " + waitTime.get()); Future<Long> waitTime2 = executor.submit(new WaitForWaiter(waiter)); sleep(20); waiter.wake(); assertTrue(waitTime2.get() < 100L, "Waited: " + waitTime2.get()); }
public boolean wake() { synchronized (lock) { if (!isWaiting) { return false; } else { woken = true; lock.notify(); return true; } } }
Waiter { public boolean wake() { synchronized (lock) { if (!isWaiting) { return false; } else { woken = true; lock.notify(); return true; } } } }
Waiter { public boolean wake() { synchronized (lock) { if (!isWaiting) { return false; } else { woken = true; lock.notify(); return true; } } } Waiter(Duration duration);  Waiter(Duration duration, Clock clock);   Waiter(Duration duration, Clock clock, Object lock); }
Waiter { public boolean wake() { synchronized (lock) { if (!isWaiting) { return false; } else { woken = true; lock.notify(); return true; } } } Waiter(Duration duration);  Waiter(Duration duration, Clock clock);   Waiter(Duration duration, Clock clock, Object lock); void doWait(); boolean wake(); void wakeOrSkipNextWait(); Duration getWaitDuration(); }
Waiter { public boolean wake() { synchronized (lock) { if (!isWaiting) { return false; } else { woken = true; lock.notify(); return true; } } } Waiter(Duration duration);  Waiter(Duration duration, Clock clock);   Waiter(Duration duration, Clock clock, Object lock); void doWait(); boolean wake(); void wakeOrSkipNextWait(); Duration getWaitDuration();  }