Results 1 to 10 of 10

Thread: What is the difference between wait and sleep method in java ?

  1. #1
    Registered
    Join Date
    May 2016
    Posts
    39

    What is the difference between wait and sleep method in java ?

    what is the difference between wait and sleep method in java?

  2. #2
    Thoughtgrid Thoughtgrid's Avatar
    Join Date
    Jul 2016
    Location
    Bangalore
    Posts
    219
    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.

  3. #3
    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.

  4. #4

  5. #5
    Registered pxljobs's Avatar
    Join Date
    Jul 2016
    Location
    Bangalore
    Posts
    290
    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

  6. #6
    Junior Registered
    Join Date
    Jul 2017
    Location
    India
    Posts
    9
    Sleep method just send your program to go somewhere to do another task

  7. #7
    Registered
    Join Date
    Nov 2016
    Posts
    649
    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.

  8. #8
    Registered
    Join Date
    Oct 2016
    Posts
    270
    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
    }
    Best Android Training | Devops Training | SQL Server Training and many more IT courses.

  9. #9
    Registered
    Join Date
    Jul 2018
    Location
    USA
    Posts
    69
    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.

  10. #10
    Registered
    Join Date
    Jul 2018
    Location
    USA
    Posts
    69
    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.

Similar Threads

  1. What are the Difference between SMO and PPC
    By Nexevo Technologi in forum Search Engine Optimization
    Replies: 0
    Last Post: 12-01-2015, 05:10 AM
  2. [SHARE]Degustation, X Rays, Winter Sleep Blogger Themes
    By silverf0x in forum The Marketplace
    Replies: 0
    Last Post: 03-02-2011, 03:27 PM
  3. Sleep
    By moonshield in forum General Chat
    Replies: 18
    Last Post: 02-15-2007, 03:27 AM
  4. Inability to sleep?
    By Fender963 in forum General Chat
    Replies: 22
    Last Post: 03-31-2006, 04:56 AM
  5. GO ON BACK TO SLEEP Touch Support 24/7/365 50% Off
    By TSGradyR in forum The Marketplace
    Replies: 0
    Last Post: 11-08-2005, 04:12 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •