Monday, 4 June 2012

Difference between wait and sleep methods?


Difference between wait and sleep methods?

The static Thread.sleep(long) method maintains control of thread execution but delays the next action until the sleep time expires.

The wait method() gives up control over thread execution indefinitely so that other threads can run.

1 comment:

  1. while wait method is present in the object class, sleep method is present in the Thread class. This means that we can't invoke sleep() method on any object. Some beginners don't understand the locking mechanism used by wait and sleep methods in java

    ReplyDelete