ExecutorCompletionService? Why do need one if we have invokeAll?

后端 未结 4 1742
渐次进展
渐次进展 2020-12-04 09:48

If we use an ExecutorCompletionService we can submit a series of tasks as Callables and get the result interacting with the CompletionService as a

4条回答
  •  眼角桃花
    2020-12-04 10:27

    Comparing by Considering only the Order of Results:

    When we use CompletionService whenever a job submitted is finished the result will be pushed to the queue (Completion Order). Then the order of the submitted jobs and the returned results is no more same. So if you are concerned about the order which tasks got executed use CompletionService

    Where As invokeAll 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.

提交回复
热议问题