Bounded Buffers
To minimize the amount of waiting time for threads that share resources and operate at the same average speeds, we can implement a bounded buffer that provides a fixed number of buffer cells into which the Producer
can place values, and from which the Consumer
can retrieve those values. (In fact, we’ve already done this with the ArrayBlockingQueue
class in Section 23.6.) If the Producer
temporarily produces values faster than the Consumer
can consume them, the Producer
can write additional values into the extra buffer cells, if any are available. This capability enables the Producer
to perform its task even though the Consumer
is not ready to retrieve the current value being produced. Similarly, if the Consumer
consumes faster ...
Get Java™ for Programmers: Deitel Developer Series, Second 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.