Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 596
Max Avatar asked Jul 18 '10 10:07

Max


1 Answers

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.

like image 95
krock Avatar answered Oct 22 '22 22:10

krock