How it works...

In this recipe, you learned how to send a list of tasks to an executor and wait for the finalization of all of them using the invokeAll() method. This method receives a list of Callable objects and returns a list of Future objects. This list will have a Future object per task. The first object in the list of Future objects will be the object that controls the first task in the list of Callable objects, the second object the second task, and so on.

The first point to take into consideration is that the type of data used for the parameterization of the Future interface in the declaration of the list that stores the result objects must be compatible with the one used to parameterize Callable objects. In this case, you used the ...

Get Java 9 Concurrency Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.