Difference between yield and sleep in java - Java @ Desk

Monday, June 3, 2013

Difference between yield and sleep in java

1) When sleep() method is called on a thread, then the thread sleeps for specified period for sure. This is not the case in case of yield method. Yield() method stops the execution of currently running thread temporarily in order to give a chance to other threads in runnable state of the same priority. If there is no such thread in runnable state of equal of high priority then the currently running thread again enters into running state.

2) Yield() method is useful for thread scheduling.

Other references on threads
Difference between sleep and wait in java
Lifecycle of thread
Difference between yield and sleep in java
Thread creation in java







No comments:

Post a Comment