Difference between wait and sleep in Java Last Updated : 16 Jun, 2021 Comments Improve Suggest changes Like Article Like Report Sleep(): This Method is used to pause the execution of current thread for a specified time in Milliseconds. Here, Thread does not lose its ownership of the monitor and resume's it's execution Wait(): This method is defined in object class. It tells the calling thread (a.k.a Current Thread) to wait until another thread invoke's the notify() or notifyAll() method for this object, The thread waits until it reobtains the ownership of the monitor and Resume's Execution. Wait()Sleep()Wait() method belongs to Object class.Sleep() method belongs to Thread class.Wait() method releases lock during Synchronization.Sleep() method does not release the lock on object during Synchronization.Wait() should be called only from Synchronized context.There is no need to call sleep() from Synchronized context.Wait() is not a static method. Sleep() is a static method. Wait() Has Three Overloaded Methods: wait()wait(long timeout)wait(long timeout, int nanos) Sleep() Has Two Overloaded Methods: sleep(long millis)millis: millisecondssleep(long millis,int nanos) nanos: Nanosecondspublic final void wait(long timeout)public static void sleep(long millis) throws Interrupted_Execption Example For Sleep Method: synchronized(monitor) { Thread.sleep(1000); Here Lock Is Held By The Current Thread //after 1000 milliseconds, current thread will wake up, or after we call that is interrupt() method } Example For wait Method: synchronized(monitor) { monitor.wait() Here Lock Is Released By Current Thread } Similarity Between Both wait() and sleep() Method: Both Make The Current Thread go Into the Not Runnable State.Both are Native Methods. The Below Code Snippet For Calling wait() and sleep() Method: Java synchronized(monitor){ while(condition == true) { monitor.wait() //releases monitor lock } Thread.sleep(100); //puts current thread on Sleep } Program: Java // Java program to demonstrate the difference // between wait and sleep class GfG{ private static Object LOCK = new Object(); public static void main(String[] args) throws InterruptedException { Thread.sleep(1000); System.out.println("Thread '" + Thread.currentThread().getName() + "' is woken after sleeping for 1 second"); synchronized (LOCK) { LOCK.wait(1000); System.out.println("Object '" + LOCK + "' is woken after" + " waiting for 1 second"); } } } OutputThread 'main' is woken after sleeping for 1 second Object 'java.lang.Object@1d81eb93' is woken after waiting for 1 second Comment More infoAdvertise with us Next Article Difference between wait and sleep in Java N nishanthec19 Follow Improve Article Tags : Java Difference Between Java-Multithreading Practice Tags : Java Similar Reads Difference Between wait() and notify() in Java The wait() and notify() are methods of the Object class. They were introduced to part ways with polling, which is the process of repeatedly checking for a condition to be fulfilled. Polling wastes CPU resources considerably, hence it is not preferred. wait() Methodwait() method is a part of java.lan 7 min read Difference Between wait() and notifyall() in Java Multithreading is a Java feature that allows concurrent execution of two or more parts of a program for maximum utilization of CPU. Each part of such program is called a thread. So, threads are light-weight processes within a process. Multi-threaded programs may often come to a situation where multi 7 min read Difference Between sleep and yield Method in Java In java if a thread doesn't want to perform any operation for a particular amount of time then we should go for the sleep() method, which causes the currently executing thread to stop for the specified number of milliseconds. Syntax : public static native void sleep( long ms) throws InterruptedExcep 4 min read Differences between wait() and join() methods in Java The wait() and join() methods are used to pause the current thread. The wait() is used in with notify() and notifyAll() methods, but join() is used in Java to wait until one thread finishes its execution. wait() is mainly used for shared resources, a thread notifies other waiting thread when a resou 2 min read What is difference between __sleep and __wakeup() in PHP ? In PHP, the __sleep and the __wakeup methods are called as magic methods. These methods are invoked or executed when we want to deal with serialization and deserialization of objects during runtime to store or save the object information in string format and again the information can be restored. _ 4 min read Like