The core argument JAVA thread pool constructor What?

In concurrent programming, the benefits of using the thread pool is to reduce overhead time and system resources on creating and destroying threads takes to solve the problem of insufficient resources. If you do not use the thread pool, it may cause the system to create a large number of threads which led to runs out of memory or problem "excessive handover".

JAVA thread pool has several core parameters, the role of these parameters are:

corePoolSize: a core number of threads, when submitting a new task to the thread pool thread pool if the number of threads currently running (including idle threads) is less than the core number of threads, it will create a new thread as the core thread to perform this task. Note: The core thread is not allowed to be destroyed, unless the setting allowCoreThreadTimeOut (true) parameter, which is a non-argument constructor.

maximumPoolSize: thread pool to allow the maximum number of threads, when submitting a new task to the thread pool, if the number of threads in the current thread pool to run (including idle threads) is greater than corePoolSize, less than maximumPoolSize, and the queue is full, it will create a the new thread to handle the task.

keepAliveTime: When the number of threads in the thread pool greater than corePoolSize, idle threads can survive the longest time.
unit: unit of time.

workQueue: Save the task queue, when the number of threads in the pool is greater than corePoolSize, save the new task to the queue.

threadFactory: thread factory, thread pool threads are created by this factory.

handler: mission refused to carry out the policy, when a thread pool can not handle the new tasks of processing strategies.

Guess you like

Origin www.cnblogs.com/gaopengpy/p/12148995.html