Please tell me its detail related to Java
Answer:-
Yield ():-
Allows any other thread of the same priority to execute (moves itself to the end of the priority queue)
Sleep ():-
Causes the currently executing thread to wait for the time (milseconds) specified.
Difference:-
When a thread invokes its yield() method, it returns to the ready state. When a task invokes its sleep()method, it returns to the waiting state.
Please tell me its detail related to Java
Hello,
Function of yield is to temporarily pause currently executing thread and allow other threads to execute. This will happen when the other thread is of same priority. The same thread will continue if there are no other threads or all other threads have low priority.
The yielded thread will get executed based on the thread scheduler.
Function of sleep is to stop execution of the currently executing thread for the specified number of seconds (milli or nano).
Thanks!