How can the wait() and notify() methods be called on Objects that are not threads?

前端 未结 9 1002
耶瑟儿~
耶瑟儿~ 2020-11-29 19:00

How can the wait() and notify() methods be called on Objects that are not Threads? That doesn\'t really make sense, does it?

Surely, it mus

9条回答
  •  忘掉有多难
    2020-11-29 19:21

    Actually, wait, notify member function should not belong to thread, the thing it should belong to name as condition variable which comes from posix thread . And you can have a look how cpp wrap this, it wrap it into a dedicated class std::condition_variable.

    Java haven't do this kind encapsulation, instead, it wrap condition variable in more high level way: monitor (put the functionality into Object class directly).

    If you don't know monitor or condition variable, well, that indeed make people confused at the beginning.

提交回复
热议问题