package com.thinker.common.thread.threadPool;

import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author lzh
 * 主要是练习线程池ThreadPoolExecutor的使用
 *
 **/
public class TestThreadPoolExecutor{
	
	private static final List<Integer> l = new LinkedList<Integer>();
	private static final int count = 10000;
	private static void go(){
		long startTime = System.currentTimeMillis();
		ThreadPoolExecutor pool = new ThreadPoolExecutor(1,1,60,TimeUnit.SECONDS,new LinkedBlockingQueue<Runnable>(count));
		final Random random = new Random();
		for(int i=0;i<count;i++){
			pool.execute(new Runnable(){
				@Override
				public void run(){
					l.add(random.nextInt());
				}
			});
		}
		pool.shutdown();
		try {
			pool.awaitTermination(1,TimeUnit.DAYS);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println((System.currentTimeMillis() - startTime)+"ms");
		System.out.println(l.size());
	}

	public static void main(String[] args){
		go();
	}

}
