Difference between the methods sleep() and wait()

Difference between the methods sleep() and wait().

sleep()wait()
It is defined in the ' Thread ' class.It is defined in the 'Object' class.
It does not release the lock or hold its monitor.It releases the lock or hold its monitor.
It is an instance of ' java.lang.Thread ' class.It is an instance of ' java.lang.Object ' class.
In this method, it goes into 'TIMED_WAITING' state without releasing the lock.In this method, after releasing the lock, it goes into 'WAITING' state.
It is a static method.It is a non-static method.
It is called within or outside the synchronized block.It is called within the synchronized block.
Java - Constructors vs. regular methods
Constructors vs. regular methods - Constructors have same name as the class and can not return a value...
What is package in JAVA?
What is package in JAVA? - Java packages help in organizing multiple modules. It helps in resolving naming conflicts when different.
Java - == vs. method equals()
== vs. method equals() - The method equals() is used to compare the values of the Strings.....
Post your comment