* @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.
* @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

几个关键参数:

1.corePoolSize:核心线程数,将会永久存在线程池中;

2.maximumPoolSize:最大线程数,如果任务队列满了,新来的任务将会额外创建临时线程来处理,但是总的线程数目不会超过这个值;

3.keepAliveTime:指的是额外创建的临时线程过期阈值;

 

线程池的参数作用:如果线程数小于corePoolSize,那么每一个任务进来都会创建线程;如果大于等于corePoolSize,那么新来的任务将会进入队列等待处理;如果队列超过阈值,那么就会新建临时线程,直到线程数到达maximumPoolSize。如果到达maximumPoolSize,那么会根据拒绝策略拒绝后来的任务。

 

线程池原本的模型就是池化一定数目的线程,然后处理用户请求,如果用户请求多了,那么就扔进队列里,等待池化的线程处理完手头工作再处理 新的请求。那么如果队列也满了,说明系统不堪重负,此时需要临时添加一下线程救急,一旦过了高峰期,这些临时线程就会被回收,这就是线程池的概念模型。