Java如何等待所有线程执行完成

走着路睡觉
  • java
小于 1 分钟


ExecutorService taskExecutor = Executors.newFixedThreadPool(4);
while(...) {
  taskExecutor.execute(new MyTask());
}
taskExecutor.shutdown();
try {
  taskExecutor.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
} catch (InterruptedException e) {
  ...
}

上次编辑于:
贡献者: zhaojingbo
Loading...