Class BlockingBuffer
Figures 23.14–23.15 demonstrate a Producer
and a Consumer
accessing an ArrayBlockingQueue
. Class BlockingBuffer
(Fig. 23.14) uses an ArrayBlockingQueue
object that stores an Integer
(line 7). Line 11 creates the ArrayBlockingQueue
and passes 1
to the constructor so that the object holds a single value to mimic the UnsynchronizedBuffer
example in Fig. 23.12. Lines 7 and 11 (Fig. 23.14) use generics, which we discussed in Chapters 16–20. We discuss multiple-element buffers in Section 23.8. Because our BlockingBuffer
class uses the thread-safe ArrayBlockingQueue
class to manage all of its shared state (the shared buffer in this case), BlockingBuffer
is itself thread safe, even though we have not implemented the synchronization ...
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.