Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does a thread become idle?

What do we mean by an idle thread? And when does it occur? Context : ThreadPoolExecutor - it says even if there is an idle thread, if the corePoolSize is small, a new thread is created

like image 502
UserInteractive Avatar asked Jan 12 '23 23:01

UserInteractive


2 Answers

In this context an idle thread is one that is owned/held by the ThreadPoolExecutor and is not currently running any Runnable/Callable.

When work is submitted to the TPE, and if an idle thread is chosen, then it becomes active and runs the Runnable/Callable. Once the Runnable/Callable completes the thread goes back to being idle (but may immediately become active again if there is more work to do and the TPE choses to use that now available thread).

like image 186
Mike Q Avatar answered Jan 17 '23 18:01

Mike Q


it simply means when ThreadPool does not have any task to be executed or has more active threads than tasks available, then the excess thread go idle. It means they simply are not available to the scheduler (aka in sleep state).

like image 29
Jatin Avatar answered Jan 17 '23 18:01

Jatin