Xuanwu Backend Tech Stack
Xuanwu Backend Tech Stack
Jan 8, 2025 · Backend Development

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.

JavaThreadPoolExecutorallowCoreThreadTimeOut
0 likes · 2 min read
Why Java ThreadPoolExecutor’s Core Threads Aren’t Recycled by Default
Full-Stack Internet Architecture
Full-Stack Internet Architecture
Jan 4, 2021 · Backend Development

Understanding ThreadPoolExecutor keepAliveTime=0 in Java

This article clarifies that setting keepAliveTime to 0 in a Java ThreadPoolExecutor causes excess idle threads beyond corePoolSize to terminate immediately, correcting the common misconception that 0 means threads live forever, and demonstrates the behavior with a concise code example.

ExecutorServiceJavaThreadPool
0 likes · 4 min read
Understanding ThreadPoolExecutor keepAliveTime=0 in Java