This article describes the Thread Pool design pattern. This is a concurrency design pattern, a category of design pattern used by software engineers, when writing computer programs.
Table of Contents
Introduction
The Thread Pool pattern is a design pattern, used in software engineering to organise the processing of a large number of queued tasks through a smaller/limited number of threads. Results can also be queued. When a thread finishes it's task it requests another. If none are available, the thread can wait or terminate.
The size of the thread pool is a tuning parameter that allows fine tuning of resource usage and responsiveness, for best results. Pooling threads helps improve performance by saving time creating the thread, however, too many idle threads can consume resources. The number of threads is based on percentage used of CPU, queued requests, and/or the number of processors in the system.
This pattern is defined as a concurrency design pattern because it relates to thread management.
Benefits
Better performance is the main gain with this pattern. Juggling the various factors that determine performance becomes more important as computers leaverage multiple processor cores.
If the number of tasks is large, creating a thread for each may become impossible or impractical, so the best answer is a thread pool.
Examples of the pattern
A web server increases of decreases the number of request processing threads, depending on load.
- A Method of Worker Thread Pooling (C++)
- Java theory and practice: Thread pools and work queues (Java)
- Multithreaded Programming with Visual Basic .NET (VB.net)
- Practical threaded programming with Python (Python)
- How to: Use a Thread Pool (C#)
See Also
Link to domain parent articles and related articles in TechNet Wiki.
Community Resources
These are the external links, including links to Microsoft and TechNet sites that are non-Wiki- Programming the Thread Pool in the .NET Framework
- .NET Framework Class Library: ThreadPool Class
- .NET Framework Developer's Guide: Threading
- The Managed Thread Pool
- Threads & Threading
References section
Use this section if you pulled source material and ideas from other sites, blogs, or forums. Make sure you have permission from authors to use their material.- [Please contribute]