Interface LightweightRecycler<T>

  • Type Parameters:
    T -

    public interface LightweightRecycler<T>
    A simple thread local object reuse facility with limited capacity and no attempt at rebalancing pooling between threads. This is meant to be put in place where churn is high, but single object allocation and footprint are not so high to justify a more sophisticated approach.
    See Also:
    ThreadLocals.createLightweightRecycler(int)
    • Method Detail

      • reuse

        default T reuse()
        Returns:
        a reusable instance, or null if none is available
      • reuseOrAllocate

        default T reuseOrAllocate​(java.util.function.Supplier<T> supplier)
        Returns:
        a reusable instance, or allocate one via the provided supplier
      • tryRecycle

        default boolean tryRecycle​(T t)
        Parameters:
        t - to be recycled, if t is a collection it will be cleared before recycling, but not cleared if not recycled
        Returns:
        true if t was recycled, false otherwise
      • available

        default int available()
        Returns:
        current count of available instances for reuse
      • capacity

        int capacity()
        Returns:
        maximum capacity of the recycler
      • get

        java.util.ArrayDeque<T> get()