“I bought this guide a few days ago to prepare for my interview with Oracle. Many of the questions they asked me were from this guide. I found this book absolutely great!”
When a thread calls yield function, it is telling the CPU specifically to allow another thread to access the resources. This means that the caller thread voluntarily is giving up resources instead of preemption by the processor’s scheduling algo.
Incase of sleep(), the caller thread wants to go to sleep for a specific period of time, regardless of what the CPU does to it. This means that even though by virtue of scheduling algorithm, the time for changing a state has arrived for the thread, if it invoked sleep(), it wont wakeup untill the specific time period that it wanted to sleep has expired. The thread will start executing immediately after the time expires.
When a object invokes yield() it returns to a ready state. But when an object invokes sleep() it does not enter a ready state.
When a thread calls yield function, it is telling the CPU specifically to allow another thread to access the resources. This means that the caller thread voluntarily is giving up resources instead of preemption by the processor’s scheduling algo.
Incase of sleep(), the caller thread wants to go to sleep for a specific period of time, regardless of what the CPU does to it. This means that even though by virtue of scheduling algorithm, the time for changing a state has arrived for the thread, if it invoked sleep(), it wont wakeup untill the specific time period that it wanted to sleep has expired. The thread will start executing immediately after the time expires.
Leave an Answer/Comment