The number of core threads in the thread pool, reserved when idle

The default number of core threads will not be cleared. keepAliveTime has no effect on the number of core threads

  • keepAliveTime: Indicates how long the thread keeps at most when there is no task execution will terminate.
  • By default, keepAliveTime will work only when the number of threads in the thread pool is greater than corePoolSize, until the number of threads in the thread pool is not greater than corePoolSize, that is, when the number of threads in the thread pool is greater than corePoolSize, if a thread is idle When the time reaches keepAliveTime, it will be terminated until the number of threads in the thread pool does not exceed corePoolSize.
  • But if the allowCoreThreadTimeOut(boolean) method is called, when the number of threads in the thread pool is not greater than corePoolSize, the keepAliveTime parameter will also work until the number of threads in the thread pool is 0;
  • allowCoreThreadTimeOut is false by default, that is, the core thread will not be closed over time, unless the thread pool is manually closed will the thread be destroyed
  • If allowCoreThreadTimeOut is set to true, the idle time of the thread reaches keepAliveTime, and all threads with the number of core threads will be closed.

Number of idle threads in the thread pool ExecutorService

Guess you like

Origin blog.csdn.net/yangshengwei230612/article/details/114638035