1.固定的线程池
1.1newFixedThreadPool
通过ExecutorService pool = Executors.newFixedThreadPool(5)进行创建
进入newFixedThreadPool如下图
public static ExecutorService newFixedThreadPool(int nThreads, ThreadFactory threadFactory) {
return new ThreadPoolExecutor(nThreads, nThreads,
0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>(),
threadFactory);
}
1.2进入ThreadPoolExecutor
使用线程工厂创建线程,并且为非守护线程
public ThreadPoolExecutor(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
BlockingQueue<Runnable> workQueue,
ThreadFactory threadFactory) {