I am working on parallel execution of 5 Tasks with Executor service, all the 5 tasks returns back with different object results-set depending upon the task.
I am using executor service for parallel execution of tasks :
List<Future<Object>> taskResults = ex.invokeAll(callables);
But how do we map the result set back with the task(s) ? It may not return back the response in the same order of callable list?
Advertisement
Answer
I found that invokeAll() sends back the response of tasks in sequential order which can be used for mapping response back to task ( callables ).
To quote the Javadoc for ExecutorService#invokeAll
:
Returns:
a list of
Future
s representing the tasks, in the same sequential order as produced by the iterator for the given task list, each of which has completed