Design of thread pool

Source: Internet
Author: User

http://blog.csdn.net/liangjingbo/article/details/2777112

The current thread pool mainly contains the following sections:

1. busy_list

The thread queue currently processing the client request, that is, the thread that is analyzing the Smart Web page

2. idle_list

Idle thread queue in current thread pool

3. request_list

When the user request arrives, it is found that there are no available threads in the thread pool, and the number of threads has reached the maximum limit (settable), this request can only be placed in the request queue, waiting for the management thread to request to the available thread, then run the task

4. manage_thread

The management thread is primarily responsible for checking to see if there is data in the request queue every second, and if so, to check whether there are currently available threads, and if so, to wake the idle thread into a working state.

If there is no data in the request queue every 10 seconds, check whether the idle thread queue needs cropping

Automatic growth and cropping rules for the thread pool:

1. Multiply the number of threads

When a user dispatches a task arrives, if it is found that there is currently no idle thread available, detects whether the thread can be created with the total number of threads currently in the current thread, and if so, the number of threads created is twice times the number of current threads

2. Single Step growth

When a user dispatches a task arrives, if it is found that there is currently no idle thread available, and the detection can not be multiplied, but the total number of threads has not reached the maximum, only one thread is created for the current task to use

3. Thread Clipping

When the management thread discovers that there is no data in the request queue in the scan (every 10 seconds), and that the number of idle threads exceeds half of the current thread, and that the total number of threads that are cropped is not less than the minimum number of threads in the thread pool, 1/4 of the total threads of the current thread pool are cropped.

For example, the current thread pool has 10 threads with a minimum number of threads of 2, and if the thread pool is idle, clipping of threads will work as follows

2 (initial state)à8 2 à6 2 à5 2 à4 2 à3 2

3 threads in the final thread pool are idle

Design of 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.