What is the Thread.State
of a thread after Thread.yield()
? Is it a Thread.State.WAITING
? Thanks.
No, the thread will still be in the RUNNABLE
state. Note that RUNNABLE
signifies that a thread is available to be run and may be either currently running or waiting its turn. Thread.STATE
does not distinguish between a thread that is currently executing and a thread that is ready to run, they are both RUNNABLE
.
A thread will only enter the WAITING
state when either wait()
, join()
or LockSupport.park()
has been called.
By calling Thread.yield()
method the currently running thread is voluntarily giving up its slice of CPU time. This thread then goes from running back into a ready state.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With