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
foggyhub
11-27-2017, 01:33 AM
Sleep method just send your program to go somewhere to do another task
damponting44
11-30-2017, 01:29 AM
Those basic distinction is wait() will be starting with object Furthermore sleep() is static system for string. The significant distinction will be that wait() discharges the lock same time sleep() doesn't releas whatever lock same time Holding up. The wait() may be utilized for inter-thread correspondence same time sleep() may be used to present stop around execution, by and large.
jackar56
02-06-2018, 07:40 AM
One key difference not yet mentioned is that while sleeping a Thread does not release the locks it holds, while waiting releases the lock on the object that wait() is called on.
synchronized(LOCK) {
Thread.sleep(1000); // LOCK is held
}
synchronized(LOCK) {
LOCK.wait(); // LOCK is not held
}
williamhills
07-25-2018, 09:44 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.
You can get more info on Stack Overflow.
williamhills
11-27-2018, 09:47 PM
Sleep () is a static method of thread class that is responsible for making the current thread in not runnable state for a particular time frame. At the same time, wait () is the method of an object class that will make the current object in not a runnable state. You can use any of them as per the nature of a program.
Powered by vBulletin® Version 4.2.2 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.