Class QueueBasedObjectPool<T>

    • Method Detail

      • ofRecyclable

        public static <T extends Recyclable> QueueBasedObjectPool<T> ofRecyclable​(java.util.Queue<T> queue,
                                                                                  boolean preAllocate,
                                                                                  Allocator<T> allocator)
        Creates a queue based pooled for types that implement Recyclable, use of(Queue, boolean, Allocator, Resetter) for other pooled object types.
        Parameters:
        queue - the underlying queue
        preAllocate - when set to true, queue will be be pre-allocated with object instance.
        allocator - a factory used to create new instances of the recyclable object. This factory is used when there are no objects in the queue and to preallocate the queue
      • of

        public static <T> QueueBasedObjectPool<T> of​(java.util.Queue<T> queue,
                                                     boolean preAllocate,
                                                     Allocator<T> allocator,
                                                     Resetter<T> resetter)
        Creates a queue based pooled for types that do not implement Recyclable, use ofRecyclable(Queue, boolean, Allocator) for types that implement Recyclable.
        Parameters:
        queue - the underlying queue
        preAllocate - when set to true, queue will be be pre-allocated with object instances fitting queue size
        allocator - a factory used to create new instances of the recyclable object. This factory is used when there are no objects in the queue and to preallocate the queue
        resetter - a reset strategy class
      • returnToPool

        protected boolean returnToPool​(T obj)
        Description copied from class: AbstractObjectPool
        Pushes object reference back into the available pooled instances
        Specified by:
        returnToPool in class AbstractObjectPool<T>
        Parameters:
        obj - recycled object to return to pool
        Returns:
        true if object has been returned to pool, false if pool is already full
      • getObjectsInPool

        public int getObjectsInPool()
        Returns:
        number of available objects in pool
      • clear

        public void clear()