I'm wondering if the main thread waits until all tasks in invokeAll() parameter finish before it continues. Here's my code and it seems that it does.
public static void main(String[] args) throws InterruptedException {
ExecutorService service = null;
try
{
service = Executors.newCachedThreadPool();
List<Callable<?>> list = new ArrayList<>();
for(int i = 0; i < 1000; i++)
{
list.add(() -> {System.out.println("Not yet"); return null;});
}
service.invokeAll(list);
System.out.println("END!"); // Output "END" at last no matter what
}
finally
{
if(service != null)
{
service.shutdown();
}
}
}
As you can see, no matter how many tasks I created, whether it is 1000 or 10000, the program still outputs "END" at last.
Can anyone confirms this information? Thank you so much!