GCDExecutorService extends AbstractExecutorService { public List<Runnable> shutdownNow() { SecurityManager sm = System.getSecurityManager(); if ( sm != null ) { sm.checkPermission(shutdownPerm); } return doWithAutoreleasePool(new Callable<List<Runnable>>() { public List<Runnable> call() { try { shutdownLock.lock(); state = State.SHUTDOWN; NSArray queuedTasks = queue.operations(); List<Runnable> result = new ArrayList<Runnable>(queuedTasks.count()); for (int i = 0; i < queuedTasks.count(); i++) { NSOperation o = Rococoa.cast(queuedTasks.objectAtIndex(i), NSOperation.class); InvocationFutureTask<?> task = tasks.get(o.id()); if ( task != null && !(o.isFinished() || o.isCancelled()) ) { result.add(task.getOriginalRunnable()); } } queue.cancelAllOperations(); tasks.clear(); terminateIfDone(queue.operationCount().intValue() == 0); return result; } finally { shutdownLock.unlock(); } } }); } GCDExecutorService(); void shutdown(); List<Runnable> shutdownNow(); boolean isShutdown(); boolean isTerminated(); boolean awaitTermination(long timeout, TimeUnit unit); void execute(Runnable command);  }
@Test public void testShutdownNow() throws InterruptedException { Object lock = new Object(); int count = 100; queueUpSomeTasks(lock, count); List<Runnable> outstandingTasks = fixture.shutdownNow(); assertEquals(count, outstandingTasks.size()); assertTrue(fixture.isShutdown()); synchronized(lock) { lock.notifyAll(); } assertTrue(fixture.awaitTermination(10, TimeUnit.SECONDS)); }