What is the difference between yield and sleep methods?

1. yield() method pauses the currently executing thread temporarily for giving a chance to the remaining waiting threads of the same priority to execute. If there is no waiting thread or all the waiting threads have a lower priority then the same thread will continue its execution. The yielded thread when it will get the chance for execution is decided by the thread scheduler whose behavior is vendor dependent.

2. sleep()-> Based on our requirement we can make a thread to be in sleeping state for a specified period of time(hope not much explanation required for our favorite method). 

People who read this post also read :


Post a Comment


Twitter Delicious Facebook Digg Stumbleupon Favorites More