Class ObjectPool<T>
- java.lang.Object
-
- io.opentelemetry.sdk.metrics.internal.state.ObjectPool<T>
-
public final class ObjectPool<T> extends java.lang.Object
A pool of objects of typeT
.When an object is borrowed from an empty pool, an object will be created by the supplied
objectCreator
and returned immediately. When the pool is not empty, an object is removed from the pool and returned. The user is expected to return the object to the pool when it is no longer used.This class is internal and is hence not for public use. Its APIs are unstable and can change at any time.
This class is not thread-safe.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.function.Supplier<T>
objectCreator
private ArrayBasedStack<T>
pool
-
Constructor Summary
Constructors Constructor Description ObjectPool(java.util.function.Supplier<T> objectCreator)
Constructs an object pool.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description T
borrowObject()
Gets an object from the pool.void
returnObject(T object)
-
-
-
Field Detail
-
pool
private final ArrayBasedStack<T> pool
-
objectCreator
private final java.util.function.Supplier<T> objectCreator
-
-
Constructor Detail
-
ObjectPool
public ObjectPool(java.util.function.Supplier<T> objectCreator)
Constructs an object pool.- Parameters:
objectCreator
- Supplier used to create an object when the pool is empty
-
-