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
Modifier and TypeMethodDescriptiondefault intintcapacity()get()default Treuse()default TreuseOrAllocate(Supplier<T> supplier) default booleantryRecycle(T t)
-
Method Details
-
reuse
- Returns:
- a reusable instance, or null if none is available
-
reuseOrAllocate
- Returns:
- a reusable instance, or allocate one via the provided supplier
-
tryRecycle
- 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
ArrayDeque<T> get()
-