public abstract class ResourcePool extends Object
TimerPool
for an example concrete implementation. Accesses
to the pool are threadsafe so there is no possibility of contention for
the resource.Modifier and Type | Field and Description |
---|---|
private Stack |
availableList |
private Stack |
reservedList |
private int |
size |
Constructor and Description |
---|
ResourcePool(int size)
Construct a new
ResourcePool of the given size. |
Modifier and Type | Method and Description |
---|---|
protected abstract Resource |
constructResource()
Construct an instance of the resource that is managed by this pool.
|
int |
getAvailableResourceCount()
Get the number of resource instances that are currently available.
|
int |
getTotalResourceCount()
Get the total number of resource instances in this pool.
|
int |
getUsedResourceCount()
Get the number of resource instances that are currently in use.
|
void |
releaseResource(Resource resource)
Release the given resource.
|
Resource |
reserveResource()
Reserve one instance of the resource.
|
private int size
private Stack reservedList
private Stack availableList
public ResourcePool(int size)
ResourcePool
of the given size.size
- The number of instances of a resource to preallocate in this
pool.public Resource reserveResource()
Resource
.public void releaseResource(Resource resource)
resource
- The Resource
to release.protected abstract Resource constructResource()
Resource
instance.public int getTotalResourceCount()
public int getUsedResourceCount()
public int getAvailableResourceCount()
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses