Class ConcurrentStripedPool<E>

  • All Implemented Interfaces:
    Iterable<E>

    public class ConcurrentStripedPool<E>
    extends Object
    implements Iterable<E>
    Concurrent pool of object based on ConcurrentLinkedDeque.
    • Constructor Detail

      • ConcurrentStripedPool

        public ConcurrentStripedPool​(int stripes,
                                     int maxPoolSize)
        Constructor.
        Parameters:
        stripes - Count of stripes.
        maxPoolSize - Max pool size.
    • Method Detail

      • recycle

        public boolean recycle​(E e)
        Pushes an element onto the pool.
        Parameters:
        e - the element to push
        Returns:
        true if the element is returned to the pool, false if the is no space at the pool.
        Throws:
        NullPointerException - if the specified element is null and this deque does not permit null elements
      • borrow

        public E borrow()
        Retrieves element from pool, or returns null if the pool is empty.
        Returns:
        the element of the pool, or null if the pool is empty.
      • forEach

        public void forEach​(Consumer<? super E> action)
        Performs the given action for each element of the pool until all elements have been processed or the action throws an exception. Exceptions thrown by the action are relayed to the caller.
        Specified by:
        forEach in interface Iterable<E>
        Parameters:
        action - The action to be performed for each element
        Throws:
        NullPointerException - if the specified action is null
      • clear

        public void clear()
        Removes all of the elements from the pool..
      • stream

        public Stream<E> stream()
        Returns a sequential Stream of the pool.
        Returns:
        a sequential Stream over the elements iof the pool.
      • resize

        public void resize​(int size)
        Parameters:
        size - New max pool size.