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();