|
soap tutorial | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectadriani.jws.template.db.ObjectPool
public abstract class ObjectPool
Abstract class managing a generic pool of objects (usually threads or database connections).
The class offers two hashtables: the locked hashtable and the unlocked hashtable.
The locked hashtable stores a reference to the "busy" objects: if the objects are DB connections,
then a "busy" object could be a connection already in use. The unlocked hashtable stores all
the "free" objects (available).
The normal life cycle of the objects should be:
1. The object is instantiated by the create()
abstract method.
2. The object is retrieved by calling the checkOut()
method.
3. The object is released by calling the checkIn()
method.
Implementation of the create()
abstract method is left to the child class and should
not be called directly: it's up to the checkOut()
method to decide if it's necessary
to create a new object (usually because the unlocked hashtable is empty) or if it's possible to
return an already existing object.
Field Summary | |
---|---|
int |
expirationTime
Sleeping time for the cleanup thread (in seconds). |
protected static java.lang.String |
leadingName
Beginning of each logging message produced by this class. |
protected static WSLogger |
logger
Retrieving the logger instance to be used for this class. |
static int |
maximum
Maximum allowed number of objects in the pool. |
Constructor Summary | |
---|---|
ObjectPool(int expirationTime)
Constructor. |
Method Summary | |
---|---|
(package private) void |
checkIn(java.lang.Object object)
Called by the user when he finishes to use an object previously retrieved using checkOut() . |
(package private) java.lang.Object |
checkOut()
Return a ready-to-use object to the user. |
(package private) void |
cleanUp()
Removes from the unlocked list all the expired objects. |
(package private) abstract java.lang.Object |
create()
Implemented by the child class (Example: see the JDBCConnectionPool class). |
(package private) abstract void |
expire(java.lang.Object object)
Implemented by the child class (Example: see the JDBCConnectionPool class). |
void |
finalize()
Method useful for debug and testing, the test the scope of the pool objects. |
java.lang.StringBuffer |
getPoolData()
Return a text message describing the status of this pool: number of locked objects, number of unlocked objects and the thread status. |
int |
getPoolSize(int max)
Accessor method. |
java.lang.String |
printObject(java.lang.Object object)
Print the serialize reference number of the input object. |
void |
setPoolSize(int max)
Mutator method. |
(package private) void |
shutdown()
Terminates the cleaner thread. |
(package private) abstract boolean |
validate(java.lang.Object object)
Implemented by the child class (Example: see the JDBCConnectionPool class). |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public int expirationTime
public static int maximum
protected static WSLogger logger
protected static java.lang.String leadingName
Constructor Detail |
---|
public ObjectPool(int expirationTime)
expirationTime
- the sleep time for the CleanUpThread
, in secondsMethod Detail |
---|
void checkIn(java.lang.Object object)
checkOut()
.
The object is removed from the locked table and put again in the unlocked table.
object
- a reference to the object to check injava.lang.Object checkOut() throws java.lang.Exception
create()
method. If we have already reached the
maximum pool capacity we return null
and log a severe message.
java.lang.Exception
void cleanUp()
expirationTime
).System.gc()
to delete all the memory footsteps.
CleanUpThread
void shutdown()
CleanUpThread
public void setPoolSize(int max)
public int getPoolSize(int max)
abstract java.lang.Object create() throws java.lang.Exception
JDBCConnectionPool
class).
java.lang.Exception
abstract boolean validate(java.lang.Object object)
JDBCConnectionPool
class).
object
- a reference to object to validateabstract void expire(java.lang.Object object)
JDBCConnectionPool
class).
object
- a reference to object to destroypublic java.lang.String printObject(java.lang.Object object)
object
- a generic Java object, e.g. MyObject@1bd4722
public java.lang.StringBuffer getPoolData()
StringBuffer
containing the printable messagepublic void finalize()
Database
class).
finalize
in class java.lang.Object
|
Build 19/03/2014 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |