Class ObjectPool<T>

  • Type Parameters:
    T - the type of the object to pool

    public abstract class ObjectPool<T>
    extends Object
    Object pool allocator that leverages a ConcurrentLinkedQueue for synchronization.
    • Constructor Detail

      • ObjectPool

        public ObjectPool()
    • Method Detail

      • allocate

        public final T allocate()
        Allocate an object from the pool or create a new one if we cannot get one from the queue.
        Returns:
        the queued or newly-created object
      • replace

        public final void replace​(T value)
        Return an object to the pool.
        Parameters:
        value - the object being returned
      • newInstance

        protected abstract T newInstance()
        Subclasses must override the object creation method.
        Returns:
        a new instance of the object.