import java.util.concurrent.*;
//实现Runnable接口来定义一个简单的线程
class TestThread implements Runnable
{
public void run()
{
for (int i = 0; i < 3 ; i++ )
{
System.out.println(Thread.currentThread().getName()
+ "的i值为:" + i);
}
}
}
public class ThreadPoolTest
{
public static void main(String[] args)
{
//创建一个具有固定线程数(6)的线程池
ExecutorService pool = Executors.newFixedThreadPool(6);
//向线程池中提交6个线程
pool.submit(new TestThread());
pool.submit(new TestThread());
pool.submit(new TestThread());
pool.submit(new TestThread());
pool.submit(new TestThread());
pool.submit(new TestThread());
pool.submit(new TestThread());
//关闭线程池
pool.shutdown();
}
}