Java thread pool

Source: Internet
Author: User
Benefits of the thread pool

1. Reduce the consumption of resources

Reduce the consumption caused by thread creation and destruction by reusing created threads

2. Improve response speed

When a task arrives, the task can be executed immediately without waiting for the thread to be created

3. Increase the manageable type of thread

Threads are scarce resources that, if created indefinitely, not only consume system resources, but also reduce system stability, using a thread pool for uniform allocation, tuning, and monitoring.

Implementation principle

When a new task is submitted to the thread pool, the thread pool process is:

1). The thread pool determines whether threads in the core line constructor are performing tasks.

If not, a new worker thread is created to perform the task. If the thread constructor the core thread is performing the task, it goes to the next process.

2). The thread pool determines whether the work queue is full.

If the work queue is not full, the newly submitted task is stored in this task column. If the work queue is full, go to the next process.

3). The thread pool determines whether threads in the thread pool are in a working state.

If not, a new worker thread is created to perform the task. If it is full, then give the saturation policy to handle the task.

Threadpoolexecutor executes the Execute () method:

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.