ExecutorService并发执行时,判断线程任务执行完成的方法

参考: https://blog.csdn.net/u012168222/article/details/52790400

https://www.cnblogs.com/stonefeng/p/5967451.html

//获取CPU数量
    static int processors = Runtime.getRuntime().availableProcessors();
    //使用线程池对学生人脸建模
    static ExecutorService fixedThreadPool = Executors.newFixedThreadPool(processors + 1);
    
     for (::) {//根据实际情况填写
                fixedThreadPool.execute(new Runnable() {
                    @Override
                    public void run() {
                        //具体操作
                    }
                });
        }
        fixedThreadPool.shutdown();
        boolean isFlag=true;
        while (isFlag){
            if (fixedThreadPool.isTerminated()){
                //具体操作
                isFlag=false;
            }else{
                //具体操作
            }
        }

猜你喜欢

转载自blog.csdn.net/baidu_21345205/article/details/80237495
今日推荐