测试线程池三种创建方法

package cn.edut.com.tarena;

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Test4 {
	public static void main(String[] args) {
		ExecutorService pool = null;
		
		//pool = Executors.newSingleThreadExecutor(); //1线程
		//pool = Executors.newCachedThreadPool() ; //400多个线程
		pool = Executors.newFixedThreadPool(10); //最多10线程
		
		for (int i = 0; i < 1000; i++) {
			pool.execute(new T1(i));
		}
		
		//关闭线程池
		pool.shutdown();
	}
	
	static class T1 implements Runnable{
		private int id ; 
		public T1(int n) {
			id = n ;
		}

		@Override
		public void run() {
			System.out.println(Thread.currentThread().getName() +" : "+ id);
		}
		
	}
	
}