sleep vs wait

sleep wait
what is it? Causes the currently executing thread to sleep (temporarily cease execution) for the specified time Causes the current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object.
In which Class? It is part of the Thread class. It belongs to the Object class.
Whether releases lock? NO YES
Use It is used to introduce pause on execution It is used for inter-thread communication
Invocation? This is a static method which puts the current thread in sleep mode. It does not need any synchronized context.
Needs to be invoked only inside a synchronized block or synchronized method.

Leave a Reply

Your email address will not be published. Required fields are marked *