Class AbstractObjectPool<T>

    • Field Detail

      • allocator

        protected final Allocator<T> allocator
      • resetter

        protected final Resetter<T> resetter
    • Constructor Detail

      • AbstractObjectPool

        protected AbstractObjectPool​(Allocator<T> allocator,
                                     Resetter<T> resetter)
    • Method Detail

      • createInstance

        public final T createInstance()
        Description copied from interface: ObjectPool
        Tries to reuse any existing instance if pool has any, otherwise creates a new un-pooled instance
        Specified by:
        createInstance in interface ObjectPool<T>
        Returns:
        object instance, either from pool or freshly allocated
      • recycle

        public final void recycle​(T obj)
        Description copied from interface: ObjectPool
        Recycles an object
        Specified by:
        recycle in interface ObjectPool<T>
        Parameters:
        obj - object to recycle
      • getGarbageCreated

        public final long getGarbageCreated()
        Specified by:
        getGarbageCreated in interface ObjectPool<T>
        Returns:
        number of times that objects could not be returned to the pool because the pool was already full
      • returnToPool

        protected abstract boolean returnToPool​(T obj)
        Pushes object reference back into the available pooled instances
        Parameters:
        obj - recycled object to return to pool
        Returns:
        true if object has been returned to pool, false if pool is already full
      • tryCreateInstance

        @Nullable
        protected abstract T tryCreateInstance()
        Tries to create an instance in pool
        Returns:
        null if pool capacity is exhausted