PDA

View Full Version : What is the difference between wait and sleep method in java ?



priya01
07-06-2016, 10:37 PM
what is the difference between wait and sleep method in java?

Thoughtgrid
09-26-2016, 10:58 PM
sleep():
It is an static method in thread class it make current thread into "Not Runnable"state for specific amount of time.
wait():
It is a method on object class make the current thread into "Not Runnable"state it is called on object not thread.

jeffronald19
12-28-2016, 09:49 PM
The fundamental difference is wait() is from Object and sleep() is static method of Thread . The major difference is that wait() releases the lock while sleep() doesn't releas any lock while waiting. The wait() is used for inter-thread communication while sleep() is used to introduce pause on execution, generally.

aceamerican
02-06-2017, 05:06 AM
major difference is that wait() releases the lock while sleep() doesn't releas any lock while waiting.

pxljobs
03-28-2017, 01:53 AM
In sleep() methods used to hold the process for few seconds
In wait() methods thread go to waiting state not come back automatically until call (notify,notify all) methods