R - the type of resource to recyclepublic class ResourceRecycler<R extends ResourceAllocationValidator>
extends java.lang.Object
A simple resource recycler that functions like a ResourcePool except that resources
are created whenever the cache is empty and resources are left for garbage collection if
there are already more than a fixed number in the buffer.
| Constructor and Description |
|---|
ResourceRecycler(ResourceFactory<R> resourceFactory,
int maxBufferedResources) |
| Modifier and Type | Method and Description |
|---|---|
R |
getResource()
Return an available resource from the pool, lazily creating a new one if
none are available.
|
void |
releaseResource(R resource)
Release a resource back to the buffer.
|
public ResourceRecycler(ResourceFactory<R> resourceFactory, int maxBufferedResources)
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 buffer