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{
                //具体操作
            }
        }

你可能感兴趣的:(Android,多线程)