public abstract class Resource extends Object implements IResource
MyResourceFactory factory = new MyResourceFactory();
ResourcePool pool = new ResourcePool(factory, 10, 50);
MyResource resource = pool.getResource();
try {
...
}finally {
resource.release();
}
| Constructor and Description |
|---|
Resource() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
acquire()
Atomically acquires a free resource.
|
abstract void |
clear()
Cleans the resource of its contents so it can be returned to the pool.
|
boolean |
isAcquired()
An indication if this resource is currently acquired.
|
boolean |
isFromPool()
An indication if this resource originated from the pool or was allocated on the fly.
|
void |
release()
Atomically sets this resource as free; usually when returning a resource to the pool.
|
void |
setAcquired(boolean acquired)
An indication if this resource is acquired.
|
void |
setFromPool(boolean fromPool)
An indication if this resource originated from the pool or was allocated on the fly.
|
public void setFromPool(boolean fromPool)
IResourcesetFromPool in interface IResourcefromPool - true if originated from the pool; false if not part
of the pool.public boolean isFromPool()
IResourceisFromPool in interface IResourcetrue if originated from the pool; false if allocated.public boolean acquire()
IResourcepublic void setAcquired(boolean acquired)
IResourcesetAcquired in interface IResourceacquired - true if resource is acquired. false if resource is
not acquired.public boolean isAcquired()
IResourceIResource.acquire(), or by use of it's status indicator IResource.setAcquired(boolean).isAcquired in interface IResourcetrue if resource is acquired. false if not yet acquired.public void release()
IResource
Before releasing the resource back into the pool, is invoked.IResource.clear()
public abstract void clear()
IResource You may use the
IResource.isFromPool() indication to decide of a special action before returning a resource to
the pool, or discard any actions on resources not returning to the pool.
clear in interface IResourceIResource.release()Copyright © GigaSpaces.