Threading - wait()

后端 未结 2 1065
深忆病人
深忆病人 2021-01-21 06:28

The wait() method on an object can be called only in the synchronized context i.e. the current thread must have a lock on the object to invoke the wait()

相关标签:
2条回答
  • 2021-01-21 06:44

    wait releases the synchronized context. From the documentation:

    The current thread must own this object's monitor. The thread releases ownership of this monitor and waits until another thread notifies threads waiting on this object's monitor to wake up (...)

    0 讨论(0)
  • 2021-01-21 06:52

    You only need to be synchronized for the duration of calling the wait() method, not for the duration of the wait time.

    0 讨论(0)
提交回复
热议问题