public class ResourcePool<R extends ResourceAllocationValidator>
extends java.lang.Object
Constructor and Description |
---|
ResourcePool(ResourceFactory<R> resourceFactory,
int maxResourcesToUse,
int maxResourceWaitTimeoutMillis) |
Modifier and Type | Method and Description |
---|---|
void |
destroyResource(R resource)
A resource should be removed from the pool either because it is no longer usable or
because it isn't needed anymore.
|
R |
getResource()
Return an available resource from the pool, lazily creating a new one if none are
available and we haven't exceeded the maximum pool size.
|
void |
releaseResource(R resource)
Release a resource back to the pool.
|
public ResourcePool(ResourceFactory<R> resourceFactory, int maxResourcesToUse, int maxResourceWaitTimeoutMillis)
public R getResource() throws java.util.concurrent.ExecutionException
java.util.concurrent.ExecutionException
- as a wrapper around any Exceptions thrown by the resource factory.public void releaseResource(R resource)
resource
- the resource to return to the poolpublic void destroyResource(R resource)
resource
- the resource we expect to find in the pool.