What is real purpose of this wait-notify thread semantics?

后端 未结 2 1636
难免孤独
难免孤独 2021-01-28 17:41

I just came across some code which uses wait-notify construct to communicate with thread defined in a class, by its other member-methods. Amusingly, after acquiring lock, all t

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-28 17:44

    As described here,

    The wait-notify pattern is used in a broad set of cases where one thread needs to tell other threads that some event has occurred. It is commonly used to implement a thread pool or producer-consumer scenario, where a particular thread or threads need to "pick up jobs" created by other threads (in this case, the "event" that has occurred is that a job has arrived for one of the threads to pick up).

提交回复
热议问题