Difference between wait() and sleep()

前端 未结 30 3127
無奈伤痛
無奈伤痛 2020-11-22 00:24

What is the difference between a wait() and sleep() in Threads?

Is my understanding that a wait()-ing Thread is still in runni

30条回答
  •  无人共我
    2020-11-22 00:47

    1. wait() is a method of Object class.
      sleep() is a method of Thread class.

    2. sleep() allows the thread to go to sleep state for x milliseconds.
      When a thread goes into sleep state it doesn’t release the lock.

    3. wait() allows thread to release the lock and goes to suspended state.
      This thread will be active when a notify() or notifAll() method is called for the same object.

提交回复
热议问题