From the course: Java EE: Concurrency and Multithreading

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

ExecutorService: invokeAny and invokeAll

ExecutorService: invokeAny and invokeAll

From the course: Java EE: Concurrency and Multithreading

ExecutorService: invokeAny and invokeAll

- [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…

Contents