线程池

创建参数。

创建

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;
}

拒绝策略

JDK 提供

相关链接

22 | Executor与线程池:如何创建正确的线程池?-极客时间arrow-up-right

最后更新于

这有帮助吗?