Class Pool.Impl<T>

  • Type Parameters:
    T - type
    All Implemented Interfaces:
    Pool<T>
    Enclosing interface:
    Pool<T>

    public abstract static class Pool.Impl<T>
    extends Object
    implements Pool<T>
    Default implementation that uses ConcurrentLinkedQueue as the data store.

    Note for Implementors

    Don't rely on the fact that this class extends from ConcurrentLinkedQueue.

    • Constructor Detail

      • Impl

        protected Impl()
        Create new Impl
    • Method Detail

      • take

        @NotNull
        public final T take()
        Gets a new object from the pool.

        If no object is available in the pool, this method creates a new one.

        Specified by:
        take in interface Pool<T>
        Returns:
        always non-null.
      • recycle

        public final void recycle​(T t)
        Returns an object back to the pool.
        Specified by:
        recycle in interface Pool<T>
        Parameters:
        t - object to put back to the pool
      • create

        @NotNull
        protected abstract T create()
        Creates a new instance of object.

        This method is used when someone wants to take an object from an empty pool.

        Also note that multiple threads may call this method concurrently.

        Returns:
        an object from an empty pool