Introduction to the core parameters of the thread pool

We all know many parameters in the thread pool. Understanding the meaning of these parameters is very important for the definition and solution of actual problems. This article will focus on: corePoolsize, maxPoolSize, keeyAliveTime, ThreadFactory, workQueue, and Handler

corePoolSize

  The number of core threads, that is, the number of threads that have survived for a long time in the medium thread pool

maxPoolSize

  Maximum number of threads, with emphasis on the maximum number of threads that can be included in a thread. The upper limit of the maximum number of threads needs to be determined according to the actual situation

keepAliveTime

  The survival time of the thread. This parameter refers to the survival time of the non-core thread. It is used to strictly control the number of threads in the thread pool to be kept within a certain range as much as possible.

ThreadFactory

  The thread creation factory, new threads are created by ThreadFactory, the system uses Executors.defaultThreadFactory created by default, the priority and group of threads created with it are the same, and he is not a daemon thread. We can also use custom threads to create factories and modify related values

WorkQueue

  There are three common types of thread work queues, as follows

  1. Direct exchange: SynchronousQueue, there are not many tasks, there is no capacity, maxPoolSize needs to be larger

  2. Unbounded queue: LinkedBlockingQueue, can generate OOM

  3. Bounded queue: ArrayBlockingQueue

 

Guess you like

Origin www.cnblogs.com/cnxieyang/p/12742966.html