- All Superinterfaces:
AsyncCloseable,AutoCloseable,Closeable
- All Known Implementing Classes:
BoundedAsyncPool
public interface AsyncPool<T> extends Closeable, AsyncCloseable
Interface declaring non-blocking object pool methods allowing to
acquire() and release(Object) objects. All
activity of a pool task outcome is communicated through the returned CompletableFuture.- Since:
- 5.1
- Author:
- Mark Paluch
-
Method Summary
Modifier and Type Method Description CompletableFuture<T>acquire()Acquire an object from thisAsyncPool.voidclear()Clear the pool.CompletableFuture<Void>clearAsync()Clear the pool.voidclose()CompletableFuture<Void>closeAsync()Requests to close this object and releases any system resources associated with it.CompletableFuture<Void>release(T object)Release an object back to thisAsyncPool.
-
Method Details
-
acquire
CompletableFuture<T> acquire()Acquire an object from thisAsyncPool. The returnedCompletableFutureis notified once the acquire is successful and failed otherwise. Behavior upon acquiring objects from an exhausted pool depends on the actual pool implementation whether requests are rejected immediately (exceptional completion withNoSuchElementException) or delayed after exceeding a particular timeout (TimeoutException). It's required that an acquired object is always released to the pool again once the object is no longer in use.. -
release
Release an object back to thisAsyncPool. The returnedCompletableFutureis notified once the release is successful and failed otherwise. When failed the object will automatically disposed.- Parameters:
object- the object to be released. The object must have been acquired from this pool.
-
clear
void clear()Clear the pool. -
clearAsync
CompletableFuture<Void> clearAsync()Clear the pool. -
close
void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
closeAsync
CompletableFuture<Void> closeAsync()Description copied from interface:AsyncCloseableRequests to close this object and releases any system resources associated with it. If the object is already closed then invoking this method has no effect.Calls to this method return a
CompletableFuturethat is notified with the outcome of the close request.- Specified by:
closeAsyncin interfaceAsyncCloseable
-