... buffer accesses are now synchronized. The synchronization is handled entirely in the blockingPut and blockingGet methods of BlockingBuffer by calling the synchronized ArrayBlockingQueue methods put and take, respectively. Thus, the Producer and Consumer Runnables are properly synchronized simply by calling the shared object’s blockingPut and blockingGet methods.

Line 15 in method blockingPut (Fig. 23.14) calls the ArrayBlockingQueue object’s put method. This method call blocks if necessary until there’s room in the buffer to place the value. Method blockingGet calls the ArrayBlockingQueue object’s take method (line 23). This method call blocks if necessary until there’s an element in the buffer to remove. Lines 16–17 and 24–25 use the ArrayBlockingQueue ...

Get Java How to Program, Early Objects, 11th 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.