ThreadPoolExecutor与newFixedThreadPool

看下两段代码就明白了:

1、ThreadPoolExecutor

final ThreadPoolExecutor tpe = new ThreadPoolExecutor(5,10,0L, TimeUnit.MILLISECONDS,new LinkedBlockingQueue<Runnable>());

	public void resolve(Serializable objectMessage) throws Exception {
		final MessageBean bean = (MessageBean)objectMessage;
		//多线程消息发送
		tpe.submit(new Runnable() {
			public void run() {
				MessageServiceImpl.service.defaultNotice(bean);
			}
		});
		
	}



2、再看下
newFixedThreadPool(最小和最大数量相等)


public static ExecutorService newFixedThreadPool(int nThreads) {   
             return new ThreadPoolExecutor(nThreads, nThreads,   
                                           0L, TimeUnit.MILLISECONDS,   
                                           new LinkedBlockingQueue<Runnable>());   
         }



由以上可知:


a、newFixedThreadPool是一个生产ThreadPoolExecutor对象的工厂。

b、newFixedThreadPool创建的是固定大小线程池的工厂。

你可能感兴趣的:(ThreadPoolExecutor与newFixedThreadPool)