Tuesday, 20 April 2021

Java: yield() method

 The yeild() method gives chance to other high-priority threads to execute. This is one of the static native method from the Thread class. 


When we call Thread.yield() in any of the running thread then the currently running thread will move to the ready state and other thread with higher priority will get a chance to execute. If another waiting thread doesn't have a higher priority than the current thread then, in that case, the current thread will continue its execution.


The Explanation from Thread class is,












Example of yield method,




No comments:

Post a Comment