Java Reference
In-Depth Information
L ISTING 7.6
Continued
// JDBC Connections.
for ( int x = 0; x < pool.size(); x++ ) {
System.err.println(“Closing JDBC Connection “ + x);
PooledConnection pcon =
(PooledConnection)pool.elementAt(x);
// If the PooledConnection is not in use, close it
if ( pcon.inUse() == false ) {
pcon.close();
}
else {
// If it's still in use, sleep for 30 seconds and
// force close.
try {
java.lang.Thread.sleep(30000);
pcon.close();
}
catch (InterruptedException ie) {
System.err.println(ie.getMessage());
}
}
}
}
}
The first steps in using the ConnectionPool are to create an instance of the object and set the
appropriate accessors. This is accomplished in an init() method of a servlet that would be
responsible for initializing the ConnectionPool . This makes the ConnectionPool available to
all future requests. An sample init() method follows:
//Initialize global variables
public void init(ServletConfig config)
throws ServletException {
super.init(config);
// Instantiate the ConnectionPool
Search WWH ::




Custom Search