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 InterruptedExceptions—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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access