BlockingQueue
解释:
1、因为fix和single中采用的队列是LinkedBlockingQueue,是链表,因此放到请求对列中的任务可以无限;
2、而newCachedThreadPool采用的是SynchronousQueue,对列中只有一个元素,所有不会无限任务请求丢进去;但是!其核心线程数设置的是Integer.MAX_VALUE,允许创建的线程数量无限;
public static ExecutorService newSingleThreadExecutor(ThreadFactory threadFactory) {
return new FinalizableDelegatedExecutorService
(new ThreadPoolExecutor(1, 1,
0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>(),
threadFactory));
}
public static ExecutorService newCachedThreadPool() {
return new ThreadPoolExecutor(0, Integer.MAX_VALUE,
60L, TimeUnit.SECONDS,
new SynchronousQueue<Runnable>());
}