Section 23.6 Producer/Consumer Relationship: ArrayBlockingQueue

ArrayBlockingQueue (p. 984) is a fully implemented buffer class from package java.util.concurrent that implements the BlockingQueue interface.

• An ArrayBlockingQueue can implement a shared buffer in a producer/consumer relationship. Method put (p. 984) places an element at the end of the BlockingQueue, waiting if the queue is full. Method take (p. 984) removes an element from the head of the BlockingQueue, waiting if the queue is empty.

ArrayBlockingQueue stores shared mutable data in an array that’s sized with an argument passed to the constructor. Once created, an ArrayBlockingQueue is fixed in size.

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.