TestExecutorService 怎么终止正在执行的任务

import java.util.concurrent.*;

public class TestExecutorService {

 /**
  * @param args
  */
 public static void main(String[] args) {
  ExecutorService executorService =  Executors.newFixedThreadPool(1);
  executorService.submit(new Runnable(){
   int s = 0;
   public void run(){
    while(true){
     System.out.println("你还运行,次数:"+(s++));    
     for (int i = 0; i < 999999999; i++) {
      //延时
     }
    }
   }
  });
  
  System.out.println("关掉 executorService");
  executorService.shutdownNow();
  System.out.println(executorService.isShutdown()); //这行输出 true
  System.out.println(executorService.isTerminated());//这行却是输出 false

  //但是上面还在打印啊
 }
}


 

类别: Uncategorized. 阅读(108). 订阅评论. TrackBack.

Leave a Reply

Be the First to Comment!

avatar
wpDiscuz