ExecutorService, how to wait for all tasks to finish

前端 未结 15 2225
攒了一身酷
攒了一身酷 2020-11-22 15:45

What is the simplest way to to wait for all tasks of ExecutorService to finish? My task is primarily computational, so I just want to run a large number of jobs

15条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-22 16:51

    Just use

    latch = new CountDownLatch(noThreads)
    

    In each thread

    latch.countDown();
    

    and as barrier

    latch.await();
    

提交回复
热议问题