Package io.javago.sync
Class Pool<T>
java.lang.Object
io.javago.sync.Pool<T>
- Type Parameters:
T- the type of objects managed by the pool
The
Pool class implements Go's sync.Pool.
A thread-safe object pool that manages a collection of reusable objects.-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Pool
Constructs a newPoolwith the given object creator.- Parameters:
creator- aSupplierthat provides new instances of the objects managed by the pool
-
-
Method Details
-
get
Retrieves an object from the pool. If the pool is empty, a new object is created using theSupplier.- Returns:
- an object from the pool, or a newly created object if the pool is empty
-
put
Returns an object to the pool, making it available for future retrieval. If the number of objects in the pool is equal toInteger.MAX_VALUE, the object will not be returned to the pool.- Parameters:
t- the object to be returned to the pool
-