Difference between wait() and sleep()

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

    wait and sleep methods are very different:

    • sleep has no way of "waking-up",
    • whereas wait has a way of "waking-up" during the wait period, by another thread calling notify or notifyAll.

    Come to think about it, the names are confusing in that respect; however sleep is a standard name and wait is like the WaitForSingleObject or WaitForMultipleObjects in the Win API.

提交回复
热议问题