Class XRProvider<I,E extends Exception>
- Type Parameters:
I- The type of provided instances (items)E- A type of exception that may be caused by the creation of new item instances.
The tool maintains a number of such items and only creates as many as are actually required at most at the same time in its application context. The items are retained and reused for subsequent operations.
In this respect, this tool is suitable for providing item types whose instantiation is relatively "expensive", which are rather unsuitable for concurrent access, but are designed for multiple or permanent use. Database or other client-server connections may be an example.
Note: this implementation cannot detect when an internal operation is taking place in the course of an operation to which the same item could be made available.
This implementation supports expiry and reinitialisation of provided items.
This implementation supports checked exceptions to occur while creating new item instances.
-
Constructor Summary
ConstructorsConstructorDescriptionXRProvider(XSupplier<? extends I, ? extends E> newItem, long maxIdle, long maxLiving) Initializes a new instance giving anXSupplierthat defines the intended initialization of a new item. -
Method Summary
Modifier and TypeMethodDescriptionfinal <R> RCalls a givenFunctionwith a parameter provided for it and returns its result.final <R,X extends Exception>
RCalls a givenXFunctionwith a parameter provided for it and returns its result.final voidRuns a givenConsumerwith a parameter provided for it.final <X extends Exception>
voidRuns a givenXConsumerwith a parameter provided for it.final intsize()Returns the number of currently unused subjects in stock.
-
Constructor Details
-
XRProvider
Initializes a new instance giving anXSupplierthat defines the intended initialization of a new item.Once an instance item is initialized it will expire and be renewed after a maximum idle time or at least after a maximum lifetime.
-
-
Method Details
-
run
-
runEx
-
get
-
getEx
-
size
public final int size()Returns the number of currently unused subjects in stock.
-