Why pool threads
Creating a thread per task is expensive: stacks, scheduler entries, and context switches add up. A thread pool executor keeps a fixed set of worker threads alive and feeds them tasks from a shared queue.
Core parameters
- Core pool size is the number of always warm threads.
- Maximum pool size caps how many threads may exist under load.
- Keep alive time lets extra threads above the core size retire when idle.
When all core threads are busy, new tasks go onto the work queue. Only when that queue is full does the pool grow toward its maximum.
The lifecycle of a task
Sizing the pool
For CPU bound work, size near the core count so threads are not fighting for cycles. For IO bound work you can run many more threads because most sit waiting. Measuring throughput beats guessing.
Key idea
A thread pool reuses a bounded set of workers, queues overflow tasks, and only grows toward its maximum when the queue fills.