RingBufferDispatcher extends SingleThreadDispatcher implements WaitingMood { @Override public boolean awaitAndShutdown(long timeout, TimeUnit timeUnit) { if (!alive()) { return false; } super.shutdown(); long start = System.nanoTime(); long timeoutNano = timeUnit.toNanos(timeout); try { disruptor.shutdown(timeout, timeUnit); } catch (TimeoutException e) { return false; } final CountDownLatch latch = new CountDownLatch(1); executor.execute(new Runnable() { @Override public void run() { executor.shutdown(); latch.countDown(); } }); try { while (!latch.await(1, TimeUnit.MILLISECONDS)) { long now = System.nanoTime(); timeoutNano -= (now - start); start = now; if (timeoutNano <= 0) { return false; } disruptor.shutdown(timeoutNano, TimeUnit.NANOSECONDS); } } catch (InterruptedException | TimeoutException e) { return false; } try { timeoutNano -= (System.nanoTime() - start); executor.awaitTermination(timeoutNano, TimeUnit.NANOSECONDS); } catch (InterruptedException e) { return false; } return true; } RingBufferDispatcher(String name); @SuppressWarnings({"unchecked"})  RingBufferDispatcher(String name,
                              int bufferSize
  ); @SuppressWarnings({"unchecked"})  RingBufferDispatcher(String name,
                              int bufferSize,
                              final Consumer<Throwable> uncaughtExceptionHandler); @SuppressWarnings({"unchecked"})  RingBufferDispatcher(String name,
                              int bufferSize,
                              final Consumer<Throwable> uncaughtExceptionHandler,
                              ProducerType producerType,
                              WaitStrategy waitStrategy); @Override boolean awaitAndShutdown(long timeout, TimeUnit timeUnit); @Override void shutdown(); @Override void forceShutdown(); @Override long remainingSlots(); @Override void nervous(); @Override void calm();  }
@Test public void testAwaitAndShutdownDoesNotHangForever() { for (int i = 0; i < 1000; i++) { RingBufferDispatcher dispatcher = new RingBufferDispatcher("dispatcher", 128); dispatcher.awaitAndShutdown(); } }