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.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default int
available()
int
capacity()
java.util.ArrayDeque<T>
get()
default T
reuse()
default T
reuseOrAllocate(java.util.function.Supplier<T> supplier)
default boolean
tryRecycle(T t)
-
-
-
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()
-
-