|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectecologylab.generic.Debug
ecologylab.generic.ResourcePool<T>
public abstract class ResourcePool<T>
This class provides access to a pool of pre-allocated resources. The pool grows and contracts throughout its lifetime to suit the number of resources necessary and to attempt to minimize memory footprints; acquire() and release() are amortized O(1) complexity (although expansion/contraction triggers may take longer). The primary way of accessing resources that are controlled by a pool are through the acquire and release methods. Every acquire should have a matching release, to ensure that resources may be recycled by later calls to acquire. Subclasses of ResourcePool ensure that the resources obtained through the acquire method are "clean", that is, they are immediately ready for use as if they were just instantiated.
| Field Summary | |
|---|---|
protected static int |
DEFAULT_POOL_SIZE
|
| Constructor Summary | |
|---|---|
protected |
ResourcePool(boolean instantiateResourcesInPool,
int initialPoolSize,
int minimumPoolSize)
Special constructor that will only instantiate the backing pool resources if the first argument is true. |
|
ResourcePool(int initialPoolSize,
int minimumPoolSize)
Creates a new ResourcePool with the specified initialPoolSize (or minimumPoolSize, minimumPoolSize > initialPoolSize) and minimum capacity. |
| Method Summary | |
|---|---|
T |
acquire()
Take a resource from the pool, making it unavailable for other segments of the program to use. |
protected abstract void |
clean(T objectToClean)
Ensure that the given Object is "clean", that is, in the state it would be in if it were just instantiated. |
protected abstract T |
generateNewResource()
Instantiates a resource of type T. |
protected void |
instantiateResourcesInPool()
|
T |
release(T resourceToRelease)
Return a resource for use by another part of the program. |
| Methods inherited from class ecologylab.generic.Debug |
|---|
classSimpleName, closeLoggingFile, debug, debug, debug, debug, debugA, debugA, debugA, debugI, debugI, debugI, error, error, getClassName, getClassName, getInteractive, getPackageName, getPackageName, getPackageName, initialize, level, level, level, logToFile, print, print, println, println, println, println, println, println, printlnA, printlnA, printlnA, printlnI, printlnI, printlnI, printlnI, setLoggingFile, show, show, superString, toggleInteractive, toString, toString, warning, warning, weird, weird |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected static final int DEFAULT_POOL_SIZE
| Constructor Detail |
|---|
protected ResourcePool(boolean instantiateResourcesInPool,
int initialPoolSize,
int minimumPoolSize)
instantiateResourcesInPool - initialPoolSize - minimumPoolSize -
public ResourcePool(int initialPoolSize,
int minimumPoolSize)
initialPoolSize - the initial size of the backing pool of objects.minimumPoolSize - the minimum size for the backing pool of objects. This is important to specify, otherwise repeatedly
aquire()'ing and release()'ing resources can have detrimental performance effects.| Method Detail |
|---|
public final T acquire()
public final T release(T resourceToRelease)
resourceToRelease -
protected abstract T generateNewResource()
protected abstract void clean(T objectToClean)
objectToClean - protected void instantiateResourcesInPool()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||