Thread Pool
Subject: Computer and Technology noun /ˈθrɛd ˌpuːl/ 1 definition
- concurrent-programming
- systems-programming
- resource-management
- parallel-computing
-
Definition (noun)
Entry #36 · UpdatedA Thread Pool is a concurrency design pattern and runtime mechanism that pre-allocates and manages a bounded collection of reusable worker threads to execute submitted tasks asynchronously. Rather than spawning and destroying an operating system thread for every incoming unit of work—which incurs significant memory allocation, context-switching, and kernel scheduling overhead—tasks are placed into a shared work queue from which idle worker threads pull and execute them. By decoupling task submission from execution and capping the maximum number of active threads, a thread pool prevents resource exhaustion under heavy load while sustaining predictable throughput and latency.
Common Types
Fixed-Size Thread Pool: Maintains a constant number of active worker threads throughout its lifetime, queuing excess tasks when all threads are busy to enforce strict upper bounds on CPU and memory consumption.
Dynamic (Cached) Thread Pool: Scales the number of worker threads up on demand during traffic spikes and reclaims idle threads after a configurable timeout, making it well suited for bursts of short-lived asynchronous tasks.
Work-Stealing Thread Pool: Assigns each worker thread its own double-ended task queue (deque) and allows idle threads to pull pending tasks from the tails of busy peers' queues, minimizing contention in recursive or divide-and-conquer workloads.
Scheduled Thread Pool: Pairs worker threads with a time-ordered delay queue to execute tasks after a specified delay or at fixed recurring intervals, supporting timers, heartbeats, and background polling.
Example
A high-traffic HTTP API server configures a fixed thread pool of 16 worker threads—matching its 16 physical CPU cores—backed by a bounded queue holding up to 1,000 pending requests. When 500 concurrent client requests arrive simultaneously, the server enqueues them rather than spawning 500 OS threads, letting the 16 workers drain the queue while keeping memory usage and context-switching overhead controlled.