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.
这里有个假设是,1分钟之内,所有task都会执行完毕, 场景符合的话这种是最简单的。
如果超时时间范围内可能执行不成功,或者无法评估执行时间的场景。
使用这个类,是不是更方便一点?
java.util.concurrent.CountDownLatch
方法可能有多种,适合场景的才是最好的。
楼上贴的stackoverflow 原答案里的其他回答也有参考价值