ThreadPoolExecutor与newFixedThreadPool

2019独角兽企业重金招聘Python工程师标准>>> ThreadPoolExecutor与newFixedThreadPool
文章图片

看下两段代码就明白了:
1、ThreadPoolExecutor

final ThreadPoolExecutor tpe = new ThreadPoolExecutor(5,10,0L, TimeUnit.MILLISECONDS,new LinkedBlockingQueue()); 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()); }





由以上可知:

a、newFixedThreadPool是一个生产ThreadPoolExecutor对象的工厂。
b、newFixedThreadPool创建的是固定大小线程池的工厂。
【ThreadPoolExecutor与newFixedThreadPool】转载于:https://my.oschina.net/weiweiblog/blog/492378

    推荐阅读