Class SharedBufferTest2
Class SharedBufferTest2
(Fig. 23.21) is identical to that of Fig. 23.17. Study the outputs in Fig. 23.21. Observe that every integer produced is consumed exactly once—no values are lost, and no values are consumed more than once. The Lock
and Condition
objects ensure that the Producer
and Consumer
cannot perform their tasks unless it’s their turn. The Producer
must go first, the Consumer
must wait if the Producer
has not produced since the Consumer
last consumed and the Producer
must wait if the Consumer
has not yet consumed the value that the Producer
most recently produced. Execute this program several times to confirm that every integer produced is consumed exactly once. In the sample output, note the highlighted ...
Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.