原代码:
ExecutorService executor = Executors.newFixedThreadPool(runSize);
修改后代码:
BlockingQueue<Runnable> workQueue=new ArrayBlockingQueue(100);
ThreadFactory threadFactory = Executors.defaultThreadFactory();
RejectedExecutionHandler rejectedExecutionHandler = new ThreadPoolExecutor.AbortPolicy();
ExecutorService executor = new ThreadPoolExecutor(runSize, runSize + 1, 3000, TimeUnit.MILLISECONDS,workQueue,threadFactory,rejectedExecutionHandler);
ThreadPoolExecutor的方法如下
public ThreadPoolExecutor(int corePoolSize,int maximumPoolSize,long keepAliveTime,TimeUnit unit,BlockingQueue<Runnable> workQueue,ThreadFactory threadFactory,RejectedExecutionHandler handler);