线程池创建的参数说明

/**
* @param corePoolSize the number of threads to keep in the pool, even
* if they are idle, unless {@code allowCoreThreadTimeOut} is set
* 核心线程数,即时线程池中有空闲线程,线程数小于此值的话,仍然会创建新的线程**
*
* @param maximumPoolSize the maximum number of threads to allow in the pool
* 最大线程数,线程池所能容的最多线程数量
*
* @param keepAliveTime when the number of threads is greater than
* the core, this is the maximum time that excess idle threads
* will wait for new tasks before terminating.
* 保活时间,当线程数量大于核心线程数,此时的空闲线程等待新任务的最长时间
*
* @param unit the time unit for the {@code keepAliveTime} argument
* 保活时间的计量单位
*
* @param workQueue the queue to use for holding tasks before they are
* executed. This queue will hold only the {@code Runnable}
* tasks submitted by the {@code execute} method.
* 工作队列,任务执行前用来持有任务的,仅持有excute方法提交的Runnable任务
*
* @param threadFactory the factory to use when the executor
* creates a new thread
* 线程工厂,在执行器创建线程时使用
*
* @param handler the handler to use when execution is blocked
* because the thread bounds and queue capacities are reached
* 处理器,由于线程bounds或者队列容量已满,导致线程阻塞时执行的逻辑
*
* @throws IllegalArgumentException if one of the following holds:

* {@code corePoolSize < 0}

* {@code keepAliveTime < 0}

* {@code maximumPoolSize <= 0}

* {@code maximumPoolSize < corePoolSize}
* 如果出现上述之一抛出的异常
*
* @throws NullPointerException if {@code workQueue}
* or {@code threadFactory} or {@code handler} is null
* 如果三者有一个为null抛出的异常
*/

ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(5,10,30, TimeUnit.SECONDS,
        new LinkedBlockingDeque(), Executors.defaultThreadFactory(),new ThreadPoolExecutor.AbortPolicy());

以上是ThreadPoolExecutor 类中注释及翻译,这是阿里代码规范推荐的线程创建方式。

你可能感兴趣的:(Java,Java,web)