Q46: How does ExecutorService manage Thread Pools, and what are the standard pool implementations?

ExecutorService decouples task submission from thread management.

  • FixedThreadPool: Fixed number of reusable threads backed by an unbounded LinkedBlockingQueue.
  • CachedThreadPool: Creates new threads dynamically as needed; reclaims idle threads after 60s. Backed by SynchronousQueue.
  • SingleThreadExecutor: Sequential single-worker execution.
  • ScheduledThreadPool: Executes tasks periodically or after delays.
Key Takeaways
  • FixedThreadPool uses an unbounded task queue (risk of OOM if overwhelmed). CachedThreadPool creates threads dynamically (risk of high thread counts).
Knowledge Check

What memory risk is associated with default Executors.newFixedThreadPool(10) under heavy load?