1. 程式人生 > >ExecutorService併發執行時,判斷執行緒任務執行完成的方法

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