From the course: Java SE 17 Developer (1Z0-829) Cert Prep

Unlock this course with a free trial

Join today to access over 25,600 courses taught by industry experts.

ExecutorService lifecycle, part 2

ExecutorService lifecycle, part 2 - Java Tutorial

From the course: Java SE 17 Developer (1Z0-829) Cert Prep

ExecutorService lifecycle, part 2

- [Instructor] Another thing that we will, of course, want to do is to actually receive the results from the tasks that we have submitted. (keyboard clicks) This piece of code will allow us to do that. Notice with this code included, we'll start by printing a message to expressly say that All jobs have been submitted to the pool. Now, handles is actually an array list containing the futures of the tasks that we have submitted. The plan will be that we will remove futures from that list as they have completed. And because of that, we will keep looping around this loop, polling to see which tasks have completed for as long as there's any tasks handles left in that array list. So we start with while (handles.size() > 0). Inside there, we go to handles and get an iterator. We actually need to be able to remove things and that means that we have to have the iterator 'cause that's the only safe way to remove an item from a list during iteration. This will be an iterator of Future of String,…

Contents