ExecutorService: invokeAny and invokeAll

您所在的位置:网站首页 invokeall和invokeany ExecutorService: invokeAny and invokeAll

ExecutorService: invokeAny and invokeAll

#ExecutorService: invokeAny and invokeAll| 来源: 网络整理| 查看: 265

- [Instructor] Okay so now that we've seen how to submit a task via the ExecutorService, let's take a look at a few other APIs. The first one is invokeAny and invokeAll. Now both of these methods help you submit a collection of tasks unlike in the previous demo where we submitted each task individually. And when you call the invokeAll method, it makes sure that it submits all the tasks, executes them and returns their output. And that output will be a list of futures this time because it's a collection of tasks okay? Now the invokeAny method is a little different. It is going to make sure that it submits all your tasks, however, it is going to return you the output of the first successful or the exceptional execution okay? So what we're going to do, we are going to go back to the project and we're going to make a very small example, where to understand how these methods work. So let's make a class and let's say, LoggingProcessor. Let this implement a callable. Let's say this returns a…



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3