Sleep vs yield in Java
GIAN Tutorials
1:11 AM
Sleep vs yield in Java Sleep and yield are two methods which are used to get CPU back from Thread to Thread Scheduler in java but they are completely different than each other. The major difference between Sleep vs yield is that sleep is more reliable than yield and it's advised to use sleep(1) instead of yield to relinquish CPU in multi-threaded Java application to give an opportunity to other threads to execute. In this Java tutorial, we will what are differences between yield and sleep in Java. But before seeing difference between sleep and Yield let's see some similarities between yield and sleep in Java Similarities between Sleep and yield in Java Here are some common things between sleep and yield method in Java programming : 1) Both yield and sleep are declared on java.lang.Thread class. 2) Both sleep() and yield() are static methods and operate on current thread. It doesn't matter which thread's object you used to call this method, both these meth