|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||
java.lang.Object | +--com.wutka.util.ResourcePool
ResourcePool holds a common set of resources that are given out in first-in-first-out order. The pool assumes that all resources are equally weighted. Since some resource pools may need to allocate additional resources when no more are available, the getOverFlowResource method can be overridden to create new ones.
When the resource is allocated, the requesting thread can associate an object with the allocated resource. One way to make use of this feature is to store the name of the method that is requesting the resource. When debugging code, you may want to look at the allocated resources and what methods have allocated them. Someties you can find methods that aren't releasing resources after allocating them.
If you allocate resources within a try block, you should release them in the finally section of the block. That way, the resource is released no matter what exception is thrown.
| Field Summary | |
protected java.util.Vector |
availableResources
The resources that are currently free |
protected java.util.Vector |
usedResourceInfo
User-defined info about a resource that has been allocated |
protected java.util.Vector |
usedResources
Resources that have been allocated out of the pool |
| Constructor Summary | |
ResourcePool()
Creates a new resource pool |
|
| Method Summary | |
void |
addResource(java.lang.Object resource)
Adds another resource to the pool |
protected void |
doNotify()
Performs a notifyAll (which requires a synchronized method) |
protected void |
doWait(long timeout)
Performs a wait for a specified number of milliseconds. |
protected void |
doWakeup()
|
java.util.Vector |
getAvailableResources()
Return a copy of the resources in the free list |
protected java.lang.Object |
getOverflowResource()
Allocates a resource when the pool is empty. |
java.lang.Object |
getResource()
Requests a resource from the pool, waiting forever if one is not available. |
java.lang.Object |
getResource(long timeout)
Requests a resource from the pool, waiting forever if one is not available. |
java.lang.Object |
getResource(java.lang.Object allocationInfo)
Requests a resource from the pool, waiting forever if one is not available. |
java.lang.Object |
getResource(java.lang.Object allocationInfo,
long timeout)
Requests a resource from the pool, waiting forever if one is not available. |
protected java.lang.Object |
getResourceFromList(java.lang.Object allocationInfo)
Grabs a resource from the free list and moves it to the used list. |
java.util.Vector |
getUsedResourceInfo()
Return a copy of the associated info for the used resources |
java.util.Vector |
getUsedResources()
Return a copy of the resources in the used list |
void |
releaseResource(java.lang.Object resource)
Releases a resource back to the pool of available resources |
void |
removeResource(java.lang.Object resource)
Removes a resource from the pool |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected java.util.Vector availableResources
protected java.util.Vector usedResources
protected java.util.Vector usedResourceInfo
| Constructor Detail |
public ResourcePool()
| Method Detail |
public void addResource(java.lang.Object resource)
resource - The resource being addedpublic void removeResource(java.lang.Object resource)
resource - The resource to be removedprotected java.lang.Object getOverflowResource()
public java.lang.Object getResource()
public java.lang.Object getResource(java.lang.Object allocationInfo)
allocationInfo - A value associated with the allocated resourcepublic java.lang.Object getResource(long timeout)
timeout - The maximum amount of time (in milliseconds)
to wait for the resourceprotected java.lang.Object getResourceFromList(java.lang.Object allocationInfo)
allocationInfo - The info to be associated with the allocated resourceprotected void doWait(long timeout)
timeout - The number of milliseconds to wait
(wait forever if timeout < 0)
public java.lang.Object getResource(java.lang.Object allocationInfo,
long timeout)
allocationInfo - A value associated with the allocated resourcetimeout - The maximum amount of time (in milliseconds)
to wait for the resourcepublic void releaseResource(java.lang.Object resource)
resource - The resource to be returned to the poolprotected void doNotify()
protected void doWakeup()
public java.util.Vector getAvailableResources()
public java.util.Vector getUsedResources()
public java.util.Vector getUsedResourceInfo()
|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||