Simple and multi-threaded (5) Taking the parallel packet thread pool as an example, the design requirement and application of thread pool are explained

Source: Internet
Author: User
Tags thread

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.

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.