ThreadPoolExcutor and invokeAll list order

北城余情 提交于 2021-01-27 11:29:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!