Why Java ThreadPoolExecutor’s Core Threads Aren’t Recycled by Default
In Java’s ThreadPoolExecutor, core threads remain alive even when idle unless the allowCoreThreadTimeOut flag is set to true, which then permits both core and non‑core threads to be reclaimed after exceeding the keepAliveTime threshold, a behavior that contradicts the pool’s design principle of minimizing thread creation overhead.
In a thread pool, there are core and non‑core threads; by default, core threads are not reclaimed even when idle. However, the ThreadPoolExecutor class provides a mechanism to recycle core threads. If the allowCoreThreadTimeOut property is set to true, a core thread will be reclaimed when its idle time exceeds keepAliveTime.
When the task queue has no tasks, ThreadPoolExecutor ’s processWorkerExit method is invoked to perform thread cleanup.
Summary:
The allowCoreThreadTimeOut parameter determines whether core threads are reclaimed (default false).
When set to true, both core and non‑core threads are reclaimed once their idle time reaches the keepAliveTime threshold.
This behavior contradicts the thread‑pool design principle of minimizing thread‑creation overhead, so the default is false.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Xuanwu Backend Tech Stack
Primarily covers fundamental Java concepts, mainstream frameworks, deep dives into underlying principles, and JVM internals.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
