Interface Buffer
The program consists of interface Buffer
(Fig. 23.9) and classes Producer
(Fig. 23.10), Consumer
(Fig. 23.11), UnsynchronizedBuffer
(Fig. 23.12) and SharedBufferTest
(Fig. 23.13). Interface Buffer
(Fig. 23.9) declares methods blockingPut
(line 6) and blockingGet
(line 9) that a Buffer
(such as UnsynchronizedBuffer
) must implement to enable the Producer
thread to place a value in the Buffer
and the Consumer
thread to retrieve a value from the Buffer
, respectively. In subsequent examples, methods blockingPut
and blockingGet
will call methods that throw InterruptedException
s—typically this indicates that a method temporarily could be blocked from performing a task. We declare each method with a throws
clause here so that we don’t ...
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.