Class ThreadLocalObjectPool<E extends AutoCloseable>
- java.lang.Object
-
- org.apache.ignite.internal.processors.query.h2.ThreadLocalObjectPool<E>
-
- Type Parameters:
E- pooled objects type
public final class ThreadLocalObjectPool<E extends AutoCloseable> extends Object
Special pool for managing limited number objects for further reuse. This pool maintains separate object bag for each thread by means ofThreadLocal.If object is borrowed on one thread and recycled on different then it will be returned to recycling thread bag. For thread-safe use either pooled objects should be thread-safe or happens-before should be established between borrowing object and subsequent recycling.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classThreadLocalObjectPool.ReusableWrapper for a pooled object with capability to return the object to a pool.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ThreadLocalObjectPool.Reusableborrow()Picks an object from the pool if one is present or creates new one otherwise.
-
-
-
Constructor Detail
-
ThreadLocalObjectPool
public ThreadLocalObjectPool(int poolSize, Supplier<E> objFactory, Consumer<E> closer, Consumer<E> recycler)- Parameters:
poolSize- number of objects which pool can contain.objFactory- factory used for new objects creation.closer- close callback.recycler- recycle callback.
-
-
Method Detail
-
borrow
public ThreadLocalObjectPool.Reusable borrow()
Picks an object from the pool if one is present or creates new one otherwise. Returns an object wrapper which could be returned to the pool.- Returns:
- reusable object wrapper.
-
-