Class BoundedConcurrentStack<E>

  • All Implemented Interfaces:
    Iterable<E>

    public class BoundedConcurrentStack<E>
    extends Object
    implements Iterable<E>
    A stack (last-in-first-out) with a configurable maximum capacity. Optimised for high concurrent read throughput.

    When the number of elements in the stack exceeds its capacity, the oldest entries are dropped. Please note that in multi-threaded environments, the size of the stack can temporarily exceed this number. This is a design decision (to avoid synchronising writes).

    • Constructor Detail

      • BoundedConcurrentStack

        public BoundedConcurrentStack​(int maxCapacity)
        Construct a new stack.
        Parameters:
        maxCapacity - maximum capacity.
    • Method Detail

      • push

        public void push​(E e)
        Push an element onto the stack.
        Parameters:
        e - to push.
      • populate

        public void populate​(Collection<E> elements)
        Populate the stack. Please note that the elements are added to the stack in the reverse order than presented by the input parameters. In other words, the first element of the input parameter will be returned first by this stack's iterator.
        Parameters:
        elements - to populate the stack with.
      • iterator

        public Iterator<E> iterator()
        Get iterator over the elements of this stack. Note that the order of iteration is the reverse of the order in which elements were added.
        Specified by:
        iterator in interface Iterable<E>
        Returns:
        iterator.
      • isEmpty

        public boolean isEmpty()
        Returns:
        true iff the stack is empty.