Connect to the simple and multi-threaded series 4,
The creation and destruction of thread objects is a need to spend system resources, through the thread pool, can avoid this problem and improve the system response time. This situation is similar to the database connection pool we often refer to.
The wide application of thread pools has enabled the support of the thread pool in the Sun's Toolkit in JDK 1.5. I plan to divide the series into two parts of design requirements and design implementations. This will be more clear. If you want to be familiar with the thread pool, then you can find the answer by designing the requirements chapter. If you want to explore the details of implementation, then in the design implementation of the article will have in-depth instructions.
In this paper, the design of thread pool is discussed with the design of concurrent bag thread pool.
Thread Pool Requirements
The ultimate goal of design and implementation is to meet demand, which is the basic principle of software development. We first consider the need for a thread pool. As a developer, our main requirement is that the thread pool is simple and easy to use. Even if your design algorithm how elegant, but to the user's complicated use of steps is not worth the candle, simple is beautiful! It is best that we do not delve into your specific implementation, through a simple interface can be applied. The second is the technical perspective, thread pool design should be more flexible, provide a good configurable manageability and scalability.
For configurable, manageable requirements, at least the following feature points are available:
The configuration of the number of threads in the thread pool.
can provide the number of dynamically tuned threads.
It is better to be able to provide elegant shundown than to shutdown the shutdown as we cut off the machine by cutting off the power.
can provide the state of a task, such as how much has been done, and how much has not been completed.
For scalability, there are several points to follow:
It can be easily extended if the need is not met.
Whether the creation of thread pool threads can suffice to extend.
The process policy of the thread pool can be extended when the submitted task load is too large.
The above is a discussion of the needs of the thread pool.