Java 执行器服务检查所有任务是否完成
在提交新的任务批之前,我想检查是否所有executor服务任务都已完成 这是我的密码:Java 执行器服务检查所有任务是否完成,java,Java,在提交新的任务批之前,我想检查是否所有executor服务任务都已完成 这是我的密码: ExecutorService executorService = Executors.newFixedThreadPool(concurrency); for(int i=0;i<batch;i++){ for(int j=0;j<concurrency;j++) { executorService.submit(ne
ExecutorService executorService = Executors.newFixedThreadPool(concurrency);
for(int i=0;i<batch;i++){
for(int j=0;j<concurrency;j++) {
executorService.submit(new DOTASK(0,loopTimes));
}
while(executorService != done){
// wait
}
System.out.println("Batch "+i+"Complete")
}
executorService.shutdown();
executorService.awaitTermination(1, TimeUnit.DAYS);
ExecutorService ExecutorService=Executors.newFixedThreadPool(并发);
for(int i=0;i是您的一个选项
ExecutorService executorService = Executors.newFixedThreadPool(concurrency);
for(int i=0;i<batch;i++){
CountLatchDown latch = new CountDownLatch(concurrency);
for(int j=0;j<concurrency;j++) {
executorService.submit(new DOTASK(0,loopTimes));
}
//in each DOTASK thread invoke latch.countDown()
latch.await();
System.out.println("Batch "+i+"Complete")
}
executorService.shutdown();
executorService.awaitTermination(1, TimeUnit.DAYS);
ExecutorService ExecutorService=Executors.newFixedThreadPool(并发);
对于(int i=0;i您可以使用CountDownLatch
或join()
您可以使用waittermination()
等待,就像您已经做的那样。您有什么问题?