Interface ObjectPool<O>
- Type Parameters:
O- The object type.
- All Known Implementing Classes:
ConcurrentQueueObjectPool
public interface ObjectPool<O>
A pool of objects.
- Author:
- Christian Kohlschütter
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceA lease for an object (obtained viaObjectPool.Lease.get()); working with the object is only permitted beforeObjectPool.Lease.close().static interfaceSanitizes a previously leased object so it can be reused by the pool.static interfaceSupplies a leased object. -
Method Summary
Modifier and TypeMethodDescriptionstatic <O> ObjectPool<O> newThreadLocalPool(ObjectPool.ObjectSupplier<@NonNull O> supplier, ObjectPool.ObjectSanitizer<@NonNull O> sanitizer) Creates a newObjectPoolthat is used within a single thread; this may or may not be implemented usingThreadLocal, however the behavior should be comparable.take()Takes an exclusive lease of an object from the pool.static <O> ObjectPool.Lease<O> unpooledLease(O obj) Returns aObjectPool.Leasethat is not backed by any object pool.
-
Method Details
-
newThreadLocalPool
static <O> ObjectPool<O> newThreadLocalPool(ObjectPool.ObjectSupplier<@NonNull O> supplier, ObjectPool.ObjectSanitizer<@NonNull O> sanitizer) Creates a newObjectPoolthat is used within a single thread; this may or may not be implemented usingThreadLocal, however the behavior should be comparable.- Type Parameters:
O- The object type.- Parameters:
supplier- The object supplier.sanitizer- The object sanitizer.- Returns:
- The object pool.
-
unpooledLease
Returns aObjectPool.Leasethat is not backed by any object pool.- Type Parameters:
O- The object type.- Parameters:
obj- The object.- Returns:
- The lease; closing/discarding has no effect.
-
take
ObjectPool.Lease<O> take()Takes an exclusive lease of an object from the pool. If no existing object is available from the pool, a new one may be provided.- Returns:
- The object.
-