What is the Thread.State of a thread after Thread.yield()?
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.
精彩评论