|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.jpeterson.pool.ObjectPool
Base functionality for implementating a pool of objects. Based on the article Build your own ObjectPool in Java to boost app speed from the June 1998 issue of JavaWorld.
Field Summary | |
static int |
DEFAULT_EXPIRATION
Default expiration is 30 seconds. |
protected java.util.Hashtable |
locked
This data element contains the objects that are currently checked out. |
protected java.util.Hashtable |
unlocked
This data element contains the objects are available in the pool. |
Constructor Summary | |
ObjectPool()
Create an ObjectPool with default expiration. |
|
ObjectPool(long expiration)
Create an ObjectPool with the specified expiration. |
Method Summary | |
protected void |
broken(java.lang.Object o)
Return a broken object to the pool. |
protected void |
checkIn(java.lang.Object o)
Return an object to the pool. |
protected java.lang.Object |
checkOut()
Retrieve an available object from the pool. |
protected abstract java.lang.Object |
create()
Called by checkOut when a new object is needed to fulfill
a request. |
protected abstract void |
expire(java.lang.Object o)
Called by checkOut when an object fails validation. |
long |
getExpiration()
Get the expiration for objects in the pool. |
void |
setExpiration(long expiration)
Set the expiration for objects in the pool. |
protected abstract boolean |
validate(java.lang.Object o)
Called by checkOut when using an object 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.Hashtable locked
Long
containing the time when the object was checked
out in milliseconds as the value in the hashtable.protected java.util.Hashtable unlocked
Long
containing the expiration time of the object in milliseconds as the
value in the hashtable.public static final int DEFAULT_EXPIRATION
Constructor Detail |
public ObjectPool()
ObjectPool
with default expiration.public ObjectPool(long expiration)
ObjectPool
with the specified expiration.expiration
- Duration that objects can be in the pool before
expiring. Expressed in milliseconds.Method Detail |
public void setExpiration(long expiration)
expiration
- Duration that objects can be in the pool before
expiring. Expressed in milliseconds.public long getExpiration()
protected abstract java.lang.Object create()
checkOut
when a new object is needed to fulfill
a request. May return null
if a new object can not be
created.null
if a new object can not be
created.protected abstract boolean validate(java.lang.Object o)
checkOut
when using an object from the pool.
Objects created via create
are assumed to be valid.
Object that are valid are assumed to be ready for use.o
- The object to validate.true if the object is "valid",
false
otherwise.
protected abstract void expire(java.lang.Object o)
checkOut
when an object fails validation.
This gives an object a chance to free any of its allocated resources.o
- The object that has just expired.protected java.lang.Object checkOut()
null
is returned.null
if no objects are available.protected void checkIn(java.lang.Object o)
o
- Object originally checked out of the pool.protected void broken(java.lang.Object o)
expire
will be called to expire the object.o
- Object originally checked out of the pool.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |