Having the following code at hand:
ExecutorService executor = Executors.newFixedThreadPool(10);
Collection collection = new ArrayList();
for (int n=1; n<100; n++)
collection.add(new MyThread(n));
try {
List<Future<Boolean>> futures = executor.invokeAll(collection);
for(Future<Boolean> future : futures){
future.get();
if (future.isDone()) {
System.out.println("true");
}
else
System.out.println("false");
}
} catch (Exception e) {
e.printStackTrace();
}
If the above is correct?
And if all future.isDone()
are true, then all of the threads have been done?
How can I make a flag, to be sure that all of them are done?
Meant as a comment on vainolo's reply but I don't have enough reputation points:
isDone
is also redundant because invokeAll
returns a list of futures for which isDone
is true. The javadocs mention this.
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