Here, we will explain a thread pool, which can be represented as a list of worker threads that, when available, will execute the required tasks. This is good when an application wants to reduce the possibly high number of threads and provide management for working threads. Another scenario where the application should benefit is when there is a large number of threads responsible for small tasks. In such situations, the overhead for creation and destruction of a large number of threads is significant, and should be avoided with a small number of threads that will execute the entire work.
We see a typical thread pool implementation in the following diagram:
We will follow this pattern when designing the ThreadPool
class. We'll use a list of threads that will be available for dispatching. In other words, the application will ask for a worker from the pool instead of creating threads. The pool manager—Dispatcher—will manage and schedule workers upon a request from an application...