Tuesday, 29 July 2014

Different between sleep() method and wait() methods in java?

Both the sleep() and wait() methods are used to suspend a thread execution for a specified time.
When sleep() is executed inside the synchronized block, the object is still under lock.
When wait() is executed , it breaks the synchronized block, so that the object lock is removed and it is available.

 Generally, sleep() is used for making a thread  to wait for some time. But wait() is used in connection with notify() or notifyAll() methods in thread communication. 

No comments:

Post a Comment