Search in sources :

Example 1 with MoreExecutors.newDirectExecutorService

use of com.google.common.util.concurrent.MoreExecutors.newDirectExecutorService in project guava by google.

the class MoreExecutorsTest method testDirectExecutorService_awaitTermination_missedSignal.

/**
   * Test for a bug where threads weren't getting signaled when shutdown was called, only when
   * tasks completed.
   */
public void testDirectExecutorService_awaitTermination_missedSignal() {
    final ExecutorService service = MoreExecutors.newDirectExecutorService();
    Thread waiter = new Thread() {

        @Override
        public void run() {
            try {
                service.awaitTermination(1, TimeUnit.DAYS);
            } catch (InterruptedException e) {
                return;
            }
        }
    };
    waiter.start();
    awaitTimedWaiting(waiter);
    service.shutdown();
    Uninterruptibles.joinUninterruptibly(waiter, 10, TimeUnit.SECONDS);
    if (waiter.isAlive()) {
        waiter.interrupt();
        fail("awaitTermination failed to trigger after shutdown()");
    }
}
Also used : MoreExecutors.newDirectExecutorService(com.google.common.util.concurrent.MoreExecutors.newDirectExecutorService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService)

Aggregations

MoreExecutors.newDirectExecutorService (com.google.common.util.concurrent.MoreExecutors.newDirectExecutorService)1 ExecutorService (java.util.concurrent.ExecutorService)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1