Logic division Thread Pool

Source: Internet
Author: User

In many systems, especially event-driven systems, maintenance of the thread pool is usually divided and managed based on different service processing types. However, the following two problems may occur during separate maintenance:

1.There is a thread pool everywhere, and each thread pool has an upper limit. However, when all thread pools reach the upper limit, the system may be unable to afford it, so the local design and restrictions cannot reach the global limit.

2.The resources in the thread pool can be reasonably used. When the thread pool is logically isolated, idle thread resources cannot be seconded to busy tasks for processing and use.

Considerations in design:

The virtual isolation thread pool requires a model to ensure protection for some processing and degrade some processing.

Design Concept:

There are two simple configuration modes: retain and limit.

For example:

The default thread pool size is set100.

AClass task settings to retain10,BClass tasks are set as restrictions50.

Assume thatA, B, CEnter the three types of tasks.

AMaximum available100Threads, where10It is exclusive (through configuration, you can choose to prioritize public or private)

BMaximum available50When the public thread (100-10 = 90) The remaining total number is less50, ThenBThe amount consumed is smaller50Assume that90Threads are not consumed.BUp50Threads. To sum up,BConsume public thread resources, and can only consume its settings at most (of course, if it exceeds the public thread, the maximum value of the public thread pool will be used as the upper limit)

CMaximum available90Threads, that is, all public threads.

When no thread resource is available for any type of request, it will be put into the queue, waiting for the thread to be available, and the queue does not distinguish the task type.

The first version is simpleJavaSee the code for download href = "http://up.2cto.com/kf/201103/2011030313340569.rar"> click here to download

Here, we will only discuss a simple design idea, which will merge the Management and Maintenance thread pool or resource pool at the minimum cost.

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.