I have N tasks, I want them to be processed in parallel with N threads. I want to wait until all tasks are finished, store results, and then run next N tasks (and so on in a loop).
Which abstractions from java util concurrency can help me here?
I looked at ExecutorService.invokeAll(), but it returns a list of futures, so I should iterate all of them in a loop until all of them are done.
I thought, there should be more straightforward way to calculate a set of tasks.
ExecutorService.invokeAll() is probably the most straightforward way of doing it.
You don't iterate over any of them to await completion. invokeAll only returns when all of them are completed. So by the time you can iterate over them, get will return immediately.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With