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.