等待所有线程都执行完毕 停止线程

int taskcount=futurelist.size();   //获取所有已提交的线程

int done=0;//已完成

while(done<taskcount){
  done=0
  for(Futrre(T) t:List){    //拿到所有的返回值futre
        isDone(t){
          done++;
          continue;
        }
    }
   try{
      Thread.sleep(500) ; //当前线程等待半秒钟  
   }catch(Interupted e){
   }
}


//判断线程是否结束
isdone(Future t){
 if(t==null  ||  t.isconcelled()  ||  t.isdone()){
        return truel;
    }
}

  

posted on 2020-01-19 21:50  潮流教父孙笑川  阅读(40)  评论(0)    收藏  举报

导航