QuestionQ20

Concurrency

Given the code fragment:

Question Image

Which code fragment invokes all callable objects in the workers set?

  • A
  • B executorService.submit(cThreads);
  • C
  • D
Explanation

ExecutorService.invokeAll(Collection<? extends Callable<T>>) submits every Callable in the given collection for execution and returns a List<Future<T>> once all tasks have completed, which is how all callable objects in a set get invoked and their results retrieved via Future.get(). invokeAny only executes the tasks until one of them completes successfully and returns that single result (not all of them), and ExecutorService.submit() accepts a single Runnable/Callable rather than a collection, so it cannot be used directly on the workers set.

Community Discussion

No comments yet. Be the first to start the discussion!