【并发编程】ThreadPoolExecutor参数详解

ThreadPoolExecutor executor = new ThreadPoolExecutor(
int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
BlockingQueue<Runnable> workQueue);


Core pool size
The lower limit of threads that are contained in the thread pool. Actually, the thread
pool starts with zero threads, but once the core pool size is reached, the number of
threads does not fall below this lower limit. If a task is added to the queue when the
number of worker threads in the pool is lower than the core pool size, a new thread
will be created even if there are idle threads waiting for tasks. Once the number of
worker threads is equal to or higher than the core pool size, new worker threads
are only created if the queue is full—i.e., queuing gets precedence over thread cre‐
ation.

Maximum pool size
The maximum number of threads that can be executed concurrently. Tasks that are
added to the queue when the maximum pool size is reached will wait in the queue
until there is an idle thread available to process the task.

Maximum idle time (keep-alive time)
Idle threads are kept alive in the thread pool to be prepared for incoming tasks to
process, but if the alive time is set, the system can reclaim noncore pool threads.
The alive time is configured in TimeUnits , the unit the time is measured in.

Task queue type
An implementation of BlockingQueue that holds
tasks added by the consumer until they can be processed by a worker thread. De‐
pending on the requirements, the queuing policy can vary.

posted on 2014-10-24 15:22  毛小娃  阅读(210)  评论(0编辑  收藏  举报

导航