KeepAliveTime: If there are currently more than corepoolsize threads in the pool, these extra threads will be terminated when the idle time exceeds KeepAliveTime.
The red Word illustrates the difference between the following two method return values.
getPoolSize():只要池中出现了大于等于corePoolSize 数量的线程,则该方法的返回值就不会小于corePoolSize 。
getActiveCount():该方法的返回值可以等于0。
After a thread with a number greater than or equal to Corepoolsize appears in the pool, the thread pool will hold at least the number of corepoolsize threads.
The above two values are equal when the number of threads in the pool is increasing, but when the thread is continuously decreasing (idle and exceeding KeepAliveTime), the minimum can be reduced to corepoolsize, while the latter can be reduced to 0
(转)isShutdown()和isTerminated()是有区别的
We can turn off the thread pool by invoking the thread pool's shutdown or Shutdownnow method, which is to traverse the worker threads in the thread pools, and then call the thread's interrupt method one at a time, so that a task that cannot respond to the interrupt may never be terminated. But there are some differences, Shutdownnow first sets the state of the thread pool to stop, then tries to stop all the threads that are executing or pausing the task, and returns a list of waiting tasks, while shutdown only sets the state of the thread pool to shutdown state. It then interrupts all threads that are not performing the task.
The IsShutDown method returns true whenever one of the two closing methods is called. The call to the Isterminaed method returns True when all tasks have been closed to indicate that the thread pool was successfully closed. As to which method we should call to close the thread pool, it should be determined by the task attributes submitted to the thread pool, usually called shutdown to close the thread pool, and shutdownnow can be called if the task is not necessarily finished.
Java thread pool