Is it a good practice to set allowCoreThreadTimeOut() in ThreadPoolExecutor? Is it a good practice to set allowCoreThreadTimeOut() in ThreadPoolExecutor? multithreading multithreading

Is it a good practice to set allowCoreThreadTimeOut() in ThreadPoolExecutor?


Every thread has an associated stack which requires some amount of memory (configurable). If your threads are in the waiting state (and even if they aren't), they are reserving that memory. It can't be used by the rest of your application. Therefore, it might make sense to stop those threads (with setAllowCoreThreadTimeout()), release the memory they had reserved, and let the ThreadPoolExecutor recreate them as needed.