Home TechnologyProgrammingJava Subscribe to RSS

What Is The Difference Between Wait() And Sleep() In Java?

Answer Question

2 Answers - Sort by: Date | Rating

    As we know java programming language supports multi threading concept. The threads are running at the same time if you want to stop execution of a thread and give the control to another thread these two functions, are supported by java for the purpose

    Wait() : This function takes parameters as milliseconds and puts the thread in wait state for the desired time of the programmer after time passes the execution starts again.

    Sleep()  : This function is also used for same purpose using his function by java you can put a thread in sleep state .sleep does not contains any parameters so the thread will not be automatically start execution It needs a wake up signal again which can be Notify().or other function are also provided by java.
          
    So the main difference in Wait() and sleep() is wait takes time parameter and wait for specific time only and sleep throws a thread in sleep mode for unspecified time.
    1 0

    Anchor0000 

    answered 3 years ago

    your answer is very nice
    Report
    Mmahesh85

    Mmahesh85

    commented 2 years ago

    You have to brush up java once again, it's making wrong path for new to the field
    Report
    Dannayya

    Dannayya

    commented 6 months ago

    Thank you for clear explanation
    Report
    Sanjoseph

    Sanjoseph

    commented 1 week ago

      Wait waits till the other process is completed or a revoke(not sure about the method's name) is called,while sleep sleeps for the specified amount of period.
      0 0

      Nlgopi 

      answered 7 months ago

        More

        More

           
           

          Ask a Question via Twitter

          Send a question to @askblurtit and we will publish it online and send you a reply everytime you receive an answer.

          Blurtit Store

          Get T-shirts, hoodies, caps and more at the Blurtit store

          Blurtit International