ThreadPoolExecutor
java.uitl.concurrent.ThreadPoolExecutor 类是线程池中最核心的一个类。
线程池底层示例图:
ThreadPoolExecutor 的构造方法:
private volatile int corePoolSize;
private volatile int maximumPoolSize;
private volatile long keepAliveTime;
private volatile boolean allowCoreThreadTimeOut;
private volatile int maximumPoolSize;
private final BlockingQueue<Runnable> workQueue;
private volatile RejectedExecutionHandler handler;
private volatile ThreadFactory threadFactory;
private static final RejectedExecutionHandler defaultHandler =new AbortPolicy();
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(