-
public class Pool<T>Base class for thread-safe pools of recycleable objects.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfacePool.FactoryUsed to create new instances of objects when needed.
-
Constructor Summary
Constructors Constructor Description Pool(int maxPoolSize, Pool.Factory<T> factory)Creates a new pool with the given pool size and factory.
-
Method Summary
Modifier and Type Method Description booleanisEmpty()Whether the pool is empty. Tget()Returns a new item, from the recycled pool if possible (if there are recycled items),or instantiating one through the factory (if we can respect the pool size).If these conditions are not met, this returns null. voidrecycle(@NonNull() T item)Recycles an item after it has been used. voidclear()Clears the pool of recycled items. final intcount()Returns the count of all items managed by this pool. final intactiveCount()Returns the active items managed by this pools, which means, itemscurrently being used. final intrecycledCount()Returns the recycled items managed by this pool, which means, itemsthat were used and later recycled, and are currently available forsecond use. StringtoString()-
-
Constructor Detail
-
Pool
Pool(int maxPoolSize, Pool.Factory<T> factory)
Creates a new pool with the given pool size and factory.- Parameters:
maxPoolSize- the max pool sizefactory- the factory
-
-
Method Detail
-
isEmpty
boolean isEmpty()
Whether the pool is empty. This means that get will returna null item, because all objects were reclaimed and not recycled yet.
-
get
@Nullable() T get()
Returns a new item, from the recycled pool if possible (if there are recycled items),or instantiating one through the factory (if we can respect the pool size).If these conditions are not met, this returns null.
-
recycle
void recycle(@NonNull() T item)
Recycles an item after it has been used. The item should come from a previous get call.
- Parameters:
item- used item
-
count
final int count()
Returns the count of all items managed by this pool. Includes- active items: currently being used- recycled items: used and recycled, available for second use
-
activeCount
final int activeCount()
Returns the active items managed by this pools, which means, itemscurrently being used.
-
recycledCount
final int recycledCount()
Returns the recycled items managed by this pool, which means, itemsthat were used and later recycled, and are currently available forsecond use.
-
-
-
-