Simple and multithreaded (6) analysis of the design and implementation of parallel packet thread pool

Source: Internet
Author: User
Tags thread

Next, in the last article introduced the thread pool design requirements and use, here we analyze the concurrent package thread pool implementation class Threadpoolexecutor design, is not feel meaningless, people have realized also analysis what? Of course is to improve our own design capabilities. For the improvement of the design ability, I think we should be able to learn from the predecessors in the concrete practice.

Summary of design ideas (such as design patterns, etc.), according to the specific context, can be used to integrate them. On the other hand, the analysis of excellent framework design and implementation is also a good way, of course, JDK design is the best learning materials. More gossip, cut into the theme, Design points:

Looking at the thread pool we implemented ourselves before JDK1.5, or the thread pool provided by concurrent, we first want two containers to maintain the threads in the thread pool and the tasks that are committed to the thread pool.

How a thread pool is associated with a task, and what task can be executed in that thread pool. So we're going to define an interface that separates the thread pool from the concrete

Task coupling, Threadpoolexecutor can accept specific tasks that implement runnable interfaces or callable interfaces (which in fact are also assembled as runnable interfaces).

Threads in the thread pool are executed from the task queue.

These are the main points of thread pool design.

In Threadpoolexecutor, there is an internal class worker, which implements the runnable, the thread in the thread pool, and it goes without saying that its run method is from the task queue

Take a task, call the task's Run method (the task implements the Runnable interface), execute the task, and so on, until there are no tasks in the queue. Look at the picture.

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.