Java / Java Concurrency and Multi Threading in Java 17 and Java 21 Interview questions
What is a thread pool?
A thread pool is a managed collection of reusable worker threads that pull tasks from a shared queue and execute them, instead of creating a brand-new thread for every task and discarding it afterward.
Reusing threads avoids the relatively high cost of OS thread creation and teardown, and lets an application bound the number of threads running concurrently, which protects the system from being overwhelmed under heavy load.
In Java, thread pools are created through the Executors factory methods or by directly configuring a ThreadPoolExecutor with a core size, maximum size, keep-alive time, and work queue.
ExecutorService pool = Executors.newFixedThreadPool(8); pool.execute(() -> doWork());
When all threads are busy, additional submitted tasks wait in the pool's internal queue until a worker becomes free, or, depending on configuration, the pool grows or rejects the task.
More Related questions...