问题
I'm working on ThreadPoolExcutor
.
I would like to know if in invokeAll
method, I can be sure that the output (Future
objects) order is going to be the same as the input (Callable
list).
List<Future<T>> invokeAll(List<Callable<T>> tasks)
回答1:
What is guaranteed is that the list of futures returned has the same order that the list's iterator you're giving. Note that this method only returns when all tasks have been completed.
Quoting invokeAll(tasks) Javadoc:
Returns: a list of Futures representing the tasks, in the same sequential order as produced by the iterator for the given task list, each of which has completed
来源:https://stackoverflow.com/questions/34158081/threadpoolexcutor-and-invokeall-list-order