Please tell me its detail related to Java

Asked By 30 points N/A Posted on -
qa-featured

Please tell me its detail related to Java

Differentiate between yield () and sleep () methods.

SHARE
Best Answer by Head Jonathon
Answered By 0 points N/A #96097

Please tell me its detail related to Java

qa-featured

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.

Best Answer
Best Answer
Answered By 0 points N/A #96098

Please tell me its detail related to Java

qa-featured

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!

Login/Register to Answer

Related Questions