Java等待所有线程运行结束
public static void main(String[] args) {
ExecutorService es = Executors.newCachedThreadPool();
for(int i=0;i<5;i++){
/* your task */
es.execute(() -> {
});
}
es.shutdown();
boolean finished = es.awaitTermination(1, TimeUnit.MINUTES);
// 所有任务都已完成或时间已到。.
}
Loading...