What is the difference between yielding and sleeping

When a task invokes its yield() method, it returns to the ready state. When a task invokesits sleep() method, it returns to the waiting state.

Showing Answers 1 - 2 of 2 Answers

sunil

  • Oct 6th, 2005
 

yield() releases lock on resources to be used by other threads, whereassleep() doesn't release lock & it will throws error it interrupted thread in sleep state.

  Was this answer useful?  Yes

Sony V George

  • Apr 5th, 2007
 

yield method is mainly used to release the lock of resource and pull up in to steady state from wait pool.

Sleep() will pull the thread to sleep for the given time. It will throws exception while trying to intrupt in b/w the sleep state

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions