Java thread pool

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.