executor.shutdown();
while (!executor.awaitTermination(24L, TimeUnit.HOURS)) {
System.out.println("Not yet. Still waiting for termination");
}
Use shutdown() + awaitTermination() combination.
EDIT:
Based on the comment of @Lital
List> calls = new ArrayList>();
calls.add(Executors.callable(new IncrementalRunable(1, aHolder)));
calls.add(Executors.callable(new IncrementalRunable(2, aHolder)));
calls.add(Executors.callable(new IncrementalRunable(3, aHolder)));
List> futures = executor.invokeAll(calls);
NOTE:
invokeAll() will not return until all the tasks are completed (either by failing or completing successful execution).