Java Reference
In-Depth Information
sleep, but wake me when something interesting happens”, and calling the notification meth-
ods means “something interesting happened”.
BoundedBuffer in Listing 14.6 implements a bounded buffer using wait and noti-
fyAll . This is simpler than the sleeping version, and is both more efficient (waking up less
frequently if the buffer state does not change) and more responsive (waking up promptly
when an interesting state change happens). This is a big improvement, but note that the in-
troduction of condition queues didn't change the semantics compared to the sleeping version.
It is simply an optimization in several dimensions: CPU efficiency, context-switch overhead,
and responsiveness. Condition queues don't let you do anything you can't do with sleeping
and polling [5] , but they make it a lot easier and more efficient to express and manage state
dependence.
Search WWH ::




Custom Search