Difference between wait() and sleep()

前端 未结 30 3883
無奈伤痛
無奈伤痛 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:36

    In simple words, wait is wait Until some other thread invokes you whereas sleep is "dont execute next statement" for some specified period of time.

    Moreover sleep is static method in Thread class and it operates on thread, whereas wait() is in Object class and called on an object.

    Another point, when you call wait on some object, the thread involved synchronize the object and then waits. :)

提交回复
热议问题