|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
Objectorg.thymeleaf.util.ResourcePool<T>
public final class ResourcePool<T>
Represents a limited set or pool of resources, which needs to be used with exclusive ownership.
Should be used in a similar fashion to the following so that resources are always released properly:
MyResource resource = myLimitedResource.allocate();
try {
// actual code using the resource
} finally {
myLimitedResource.release(resource);
}
| Nested Class Summary | |
|---|---|
static interface |
ResourcePool.IResourceFactory<T>
Objects implementing this interface are in charge of creating the resources that conform the pool. |
| Constructor Summary | |
|---|---|
ResourcePool(Collection<T> resources)
|
|
ResourcePool(ResourcePool.IResourceFactory<T> resourceFactory,
int poolSize)
|
|
| Method Summary | |
|---|---|
T |
allocate()
Allocates and returns a resource from the pool. |
void |
discardAndReplace(T resource)
Discards an allocated resource and forces the resource factory to create a new one, if a resource factory has been specified during pool instantiation. |
void |
release(T resource)
Releases a previously allocated resource. |
| Methods inherited from class Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ResourcePool(Collection<T> resources)
public ResourcePool(ResourcePool.IResourceFactory<T> resourceFactory,
int poolSize)
| Method Detail |
|---|
public T allocate()
Allocates and returns a resource from the pool.
Blocks until a resource is available when a resource is not available immediately.
public void release(T resource)
Releases a previously allocated resource.
Might also be used to introduce new resources, e.g. in place of a broken resource.
resource - the resource to be released and returned to the pool.public void discardAndReplace(T resource)
Discards an allocated resource and forces the resource factory to create a new one, if a resource factory has been specified during pool instantiation.
If a resource factory has not been specified, this method will raise an IllegalStateException.
resource - the resource to be discarded and substituted with a
new one.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||