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;
}
corePoolSize: 核心线程数量,也就是允许同时运行的最大线程数。如果执行了线程池的prestartAllCoreThreads()方法,线程池会提前创建并启动所有核心线程。
maximumPoolSize: 允许创建的最大线程数, 数量大于corePoolSize, 那么剩下的线程就要放到下面提到的阻塞队列中。
workQueue: 存放等待的线程。
keepAliveTime:线程没有任务时,最多保持多久就停止。
threadFactory: 用于创建线程的工厂
handler: 拒绝处理任务的策略
线程池如何管理线程。
threadlocal内部实现:每个thread分配一个独立的map。
gcroot有哪些
虚拟机栈引用的对象
本地方法栈中引用的对象
方法区里类的静态变量、常量