@Test public void testAwaitTermination() throws Exception { int count=100; Object lock = new Object(); queueUpSomeTasks(lock, count); List<Runnable> outstandingTasks = fixture.shutdownNow(); assertEquals(count, outstandingTasks.size()); assertTrue(fixture.isShutdown()); synchronized(lock) { lock.notifyAll(); } assertTrue(fixture.awaitTermination(5, TimeUnit.SECONDS)); assertTrue(fixture.isTerminated()); }
public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { long wait = unit.toNanos(timeout); shutdownLock.lock(); try { while ( !isTerminated() ) { if ( wait <= 0) { return false; } wait = shutdownCondition.awaitNanos(wait); terminateIfDone(queue.operationCount().intValue() == 0); } return true; } finally { shutdownLock.unlock(); } }
GCDExecutorService extends AbstractExecutorService { public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { long wait = unit.toNanos(timeout); shutdownLock.lock(); try { while ( !isTerminated() ) { if ( wait <= 0) { return false; } wait = shutdownCondition.awaitNanos(wait); terminateIfDone(queue.operationCount().intValue() == 0); } return true; } finally { shutdownLock.unlock(); } } }
GCDExecutorService extends AbstractExecutorService { public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { long wait = unit.toNanos(timeout); shutdownLock.lock(); try { while ( !isTerminated() ) { if ( wait <= 0) { return false; } wait = shutdownCondition.awaitNanos(wait); terminateIfDone(queue.operationCount().intValue() == 0); } return true; } finally { shutdownLock.unlock(); } } GCDExecutorService(); }
GCDExecutorService extends AbstractExecutorService { public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { long wait = unit.toNanos(timeout); shutdownLock.lock(); try { while ( !isTerminated() ) { if ( wait <= 0) { return false; } wait = shutdownCondition.awaitNanos(wait); terminateIfDone(queue.operationCount().intValue() == 0); } return true; } finally { shutdownLock.unlock(); } } GCDExecutorService(); void shutdown(); List<Runnable> shutdownNow(); boolean isShutdown(); boolean isTerminated(); boolean awaitTermination(long timeout, TimeUnit unit); void execute(Runnable command); }
GCDExecutorService extends AbstractExecutorService { public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { long wait = unit.toNanos(timeout); shutdownLock.lock(); try { while ( !isTerminated() ) { if ( wait <= 0) { return false; } wait = shutdownCondition.awaitNanos(wait); terminateIfDone(queue.operationCount().intValue() == 0); } return true; } finally { shutdownLock.unlock(); } } GCDExecutorService(); void shutdown(); List<Runnable> shutdownNow(); boolean isShutdown(); boolean isTerminated(); boolean awaitTermination(long timeout, TimeUnit unit); void execute(Runnable command);  }