|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectbeowulf.util.pooling.ReflectionPool
This implementation of Pool uses reflection to generate new instances of a
particular object. All of the methods are synchronized making it thread
safe, and there is very little overhead involved in checking an instance in
or out. The pool size will never shrink, so this implementation is not
recommended for server programs or daemon programs. The checkIn()
method does not provide any type checking, so it is up to the user
to ensure proper use. There may be substantial overhead for the first few
calls to checkOut, but provided the user checks these objects
back in, this will not happen again.
| Field Summary | |
protected Vector |
freeObjects
The list of unused instances. |
protected Class |
poolClass
The class of objects to be instantianted. |
| Constructor Summary | |
ReflectionPool(Class newPoolClass)
This will create a new Pool that will pool instances of the Class given to the constructor. |
|
ReflectionPool(String classname)
This will create a new Pool that will pool instances of the Class that is represented by the String given to the constructor. |
|
| Method Summary | |
void |
checkIn(Object returnedObject)
This implementation of Pool will simply add the returned object to an instance of java.util.Vector. |
Object |
checkOut()
This Pool implementation will first look in the java.util.Vector
of unused objects. |
Class |
getPoolClass()
This will return a reference to the class that this Pool instance is associated with. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected Class poolClass
protected Vector freeObjects
| Constructor Detail |
public ReflectionPool(String classname)
throws ClassNotFoundException
ClassNotFoundException will be thrown.
classname - The fully qualified path name of the class to be
associated with this Pool.
ClassNotFoundException - This will be thrown if classname
is not a fully qualified path name of a valid class.public ReflectionPool(Class newPoolClass)
newPoolClass - The class that will be associated with this Pool.| Method Detail |
public Class getPoolClass()
getPoolClass in interface Poolpublic Object checkOut()
java.util.Vector
of unused objects. If one exists, it will be removed from the
java.util.Vector and returned in constant time with very
little overhead. If not, reflection will be used to instantiate a new
instance of the associated class. This instance will be returned.
checkOut in interface Poolpublic void checkIn(Object returnedObject)
java.util.Vector. The operation will be done
in constant time with very little overhead. This implementation does
not do any checking to ensure that returnedObject is an
instance of the class that is associated with this Pool. This is done
for efficiency reasons.
checkIn in interface PoolreturnedObject - The object to be checked back in.
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||