boolean awaitTermination(long timeout,TimeUnit unit)throws InterruptedException
Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.
The assumption here is that all tasks will be executed within 1 minute. If the scenario is met, this is the simplest. If the execution may not be successful within the timeout period, or the execution time cannot be evaluated. Is it more convenient to use this class?
java.util.concurrent.CountDownLatch
There may be many methods, and the one that suits the scene is the best. The other answers in the original stackoverflow answer posted upstairs are also of reference value
Original answer on StackOverflow.
The assumption here is that all tasks will be executed within 1 minute. If the scenario is met, this is the simplest.
If the execution may not be successful within the timeout period, or the execution time cannot be evaluated.
Is it more convenient to use this class?
There may be many methods, and the one that suits the scene is the best.
The other answers in the original stackoverflow answer posted upstairs are also of reference value