Java Reference
In-Depth Information
L ISTING 7.6
Continued
System.err.println(cnfe.getMessage());
}
catch (Exception e) {
System.err.println(e.getMessage());
}
}
// Adds the PooledConnection to the pool
private void addConnection(PooledConnection value) {
// If the pool is null, create a new vector
// with the initial size of “size”
if ( pool == null ) {
pool = new Vector(size);
}
// Add the PooledConnection Object to the vector
pool.addElement(value);
}
public synchronized void releaseConnection(Connection con) {
// find the PooledConnection Object
for ( int x = 0; x < pool.size(); x++ ) {
PooledConnection pcon =
(PooledConnection)pool.elementAt(x);
// Check for correct Connection
if ( pcon.getConnection() == con ) {
System.err.println(“Releasing Connection “ + x);
// Set its inuse attribute to false, which
// releases it for use
pcon.setInUse(false);
break;
}
}
}
// Find an available connection
public synchronized Connection getConnection()
throws Exception {
Search WWH ::




Custom Search