Beginner Topic 5 of 51 Concurrency & Parallelism
Thread Pools
Reusing a fixed set of worker threads.
How it works
A thread pool maintains a fixed or bounded set of worker threads that take tasks from a shared queue, avoiding the cost of creating and destroying a thread for each task and bounding resource use. Tasks are submitted to the pool and executed when a worker is free. Pool sizing depends on the workload: roughly the number of cores for CPU-bound work and more for I/O-bound work. Variants include cached pools, scheduled pools and work-stealing pools such as ForkJoinPool.
Where it is used
Web servers, database connection handlers, parallel frameworks, build tools and task runners use pools such as Java's ExecutorService, Python's ThreadPoolExecutor and .NET's ThreadPool.
Common pitfall
Pools that are too small cause queued latency and deadlock when tasks wait for other tasks in the same pool; too big waste memory and cause contention. Unbounded queues hide overload and exhaust memory. Blocking tasks starve CPU-bound ones when mixed. Use bounded queues with rejection policies, separate pools for different workloads and shut pools down gracefully.
Where it fits in the course
Thread Pools is topic 5 of 51 in Concurrency & Parallelism, rated Beginner. It follows Threads in Practice. The next topic is Thread Safety.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the Concurrency & Parallelism quiz.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the Concurrency & Parallelism quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is Thread Pools?
Where do people use Thread Pools?
What is the most common mistake with Thread Pools?
What should I learn before this topic?
How can I practice it?
Is Thread Pools hard to learn?
How long does it take to learn Thread Pools?
Which topics are related to Thread Pools?
What should I study after Thread Pools?
Related topics
- Threads in Practice (Concurrency & Parallelism)
- Thread Safety (Concurrency & Parallelism)
- Amdahl's Law (Concurrency & Parallelism)
- Shared State Hazards (Concurrency & Parallelism)