public ThreadPoolExecutor(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
BlockingQueue<Runnable> workQueue,
ThreadFactory threadFactory,
RejectedExecutionHandler handler) {
if (corePoolSize < 0 ||
maximumPoolSize <= 0 ||
maximumPoolSize < corePoolSize ||
keepAliveTime < 0)
throw new IllegalArgumentException();
if (workQueue == null || threadFactory == null || handler == null)
throw new NullPointerException();
this.acc = System.getSecurityManager() == null ?
null :
AccessController.getContext();
this.corePoolSize = corePoolSize;
this.maximumPoolSize = maximumPoolSize;
this.workQueue = workQueue;
this.keepAliveTime = unit.toNanos(keepAliveTime);
this.threadFactory = threadFactory;
this.handler = handler;
}
上面就是线程池源码核心类
ThreadPoolExecutor
参数解读
- int corePoolSize 核心线程数大小,
- int maximumPoolSize, 线程池总大小
- long keepAliveTime, 线程空闲后保持时间
- TimeUnit unit, 时间维度,秒,分,小时
- BlockingQueue workQueue, 任务缓存的阻塞队列
- ThreadFactory threadFactory, 创建线程的工程类
- RejectedExecutionHandler handler 抛弃策略当线程放不下的时候,如何处理