package pool;
import java.util.concurrent.*;
public class Machine implements Runnable{
  private int id;
  public Machine(int id){this.id=id;}
  public void run(){
    for(int a=0;a<10;a++){
      System.out.println("当前线程："+Thread.currentThread().getName()+"  当前Machine"+id+":a="+a);
      Thread.currentThread().yield();
    }
  }
  public static void main(String args[])throws Exception{
    ExecutorService service=Executors.newFixedThreadPool(2);
    for(int i=0;i<5;i++){
      service.execute(new Machine(i));
      //service.submit(new Machine(i));
    }
    System.out.println("任务提交结束");
    service.shutdown();  
    System.out.println("等已经提交的任务完成后，服务会关闭");
  }
}



/****************************************************
 * 作者：孙卫琴                                     *
 * 来源：<<Java面向对象编程>>                       *
 * 技术支持网址：www.javathinker.net                *
 ***************************************************/

 


