package thread;
import org.junit.Test;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
* Created by guofeipeng on 15/11/17.
* 线程池测试
*/
public class TestThreadPool {
@Test
public void testThradPool(){
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(30, 50, 60L, TimeUnit.SECONDS,
new SynchronousQueue<Runnable>());
for(int i = 0 ; i < 10 ; i++){
Thread t = new Thread(new Task());
t.setName("thread" + i);
threadPoolExecutor.execute(t);
}
threadPoolExecutor.shutdown();
while (!threadPoolExecutor.isTerminated()) {
}
}
class Task implements Runnable{
@Override
public void run() {
System.out.println("task " + Thread.currentThread().getName());
}
}
}