🔥 Burn Fat Fast. Discover How! 💪

What is the difference between wait() and sleep()? #threads #o | Java Tech News

What is the difference between wait() and sleep()?
#threads #object
• The fundamental difference is that wait() is non static method of Object and sleep() is a static method of Thread.
• The major difference is that wait() releases the lock while sleep() doesn’t release any lock while waiting.
• wait() is used for inter-thread communication while sleep() is used to introduce a pause on execution, generally.
• wait() should be called from inside synchronise or else we get an IllegalMonitorStateException, while sleep() can be called anywhere.
• To start a thread again from wait(), you have to call notify() or notifyAll() indefinitely. As for sleep(), the thread gets started definitely after a specified time interval.

Similarities
• Both make the current thread go into the Not Runnable state.
• Both are native methods.
https://stackoverflow.com/questions/1036754/difference-between-wait-and-sleep