私有Executor执行任务

boolean checkMain(Set<> hosts,long timeout, TimeUnit unit) throws InterruptedException{
    
    
  ExecutorService exec = new CachedThreadPool();

  final AtomicBoolean hasNewMail = new AtomicBoolean(false);

  try{
    
    
    for(final String host : hosts){
    
    
      exec.execute(
        new Runnable(){
    
    
          public void run(){
    
    
            if(checkMain(host)){
    
    
              hasMail(true);
            }
          }
        }
      );
    }
  }finally{
    
    
    exec.shutdown();
    exec.awaitTermination(timeout,unit);'
  }

  return hasNewMail.get();
}

猜你喜欢

转载自blog.csdn.net/weixin_37632716/article/details/118638610