yield (): suppose there are three threads t1, t2 and t3. Thread t1 receives the processor and starts its execution, and threads t2 and t3 are in Ready / Runnable state. The completion time for stream t1 is 5 hours, and the completion time for t2 is 5 minutes. Since t1 will complete its execution after 5 hours, t2 must wait 5 hours to simply complete the 5 minute operation. In such scenarios, when one thread takes too much time to complete its execution, we need a way to prevent the intermediate thread from executing if something important is expected. Yeild () helps us with this. yield () basically means that the thread is not doing anything particularly important, and if you need to start any other threads or processes, they should be executed. Otherwise, the current thread will continue to work.
You can use the Thread.sleep () method to pause the execution of the current thread for a specified time in milliseconds. No other will be executed at this time.
Bachan Joseph Nov 14 '18 at 17:28 2018-11-14 17:28
source share