public class BoundedBuffer<T> extends Object implements Iterable<T>
A thread safe bounded buffer.
The idea of this class is that it retains only the last elements added to the buffer up to a determined size, but it is possible to make snapshot of the buffer elements and iterate over them with a neglectable impact on synchronization.
It maintains a linked list. When a new element is added, the first element will have for successor that new element. If the number of elements is greater than the max size then the last element is discarded.
When a snapshot for iteration is required, the class only needs to keep a reference to the last element of the list and keep also the actual size of the list. The copy is made in an atomic manner for consistency. Note that this class expose only a notion of iterator to its client instead of a notion of list as iterator have a notion of being short lived objects. Indeed keeping a reference on an iterator would create a memory leak and so this class must be used with caution.
| Constructor and Description |
|---|
BoundedBuffer(int maxSize) |
public int getMaxSize()
public void add(T t)
t - the element to addCopyright © 2025 JBoss by Red Hat. All Rights Reserved.