In java, we use WAITING and TIMED_WAITING for a synchronized object. If the thread is in WAITING state, another thread should wake it using notify()
TIMED_WAITING is the same as WAITING, but it will continue automatically when the specified time parameter is exceeded.
A thread is in the BLOCKED state when the thread wants to execute, but it cannot work due to another thread that is running on the same synchronized object.
Thus, we can see that TIMED_WAITING is the same as WAITING, but will stop after a certain time.
But why did java separate BLOCKED and WAITING? This is due to the fact that they are different, as indicated above. BLOCKED means that the thread is running, but it cannot work, due to the start of another thread. And the WAITING state is just waiting for a call to notify()
Why C # has only one state is just a design decision. All java methods show that the thread is not in runnable state, and C # just decided to combine these three states in one variant: WaitSleepJoin
source share