Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 执行器服务检查所有任务是否完成_Java - Fatal编程技术网

Java 执行器服务检查所有任务是否完成

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

在提交新的任务批之前,我想检查是否所有executor服务任务都已完成 这是我的密码:

     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()
等待,就像您已经做的那样。您有什么问题?