Second, get and return to the connection
DBConnectionManager provides a getConnection () method and FREECONNECTION method, which has a client program. All methods are used to connect pool names and call specific connection pool objects.
Public Connection getConnection (String name) {
DBConnectionPool Pool = (dbconnectionpool) pools.get (name);
IF (pool! = null) {
Return pool.getConnection ();
}
Return NULL;
}
Public Connection getConnection (String Name, long time) {
DBConnectionPool Pool = (dbconnectionpool) pools.get (name);
IF (pool! = null) {
Return Pool.getConnection (TIME);
}
Return NULL;
}
Public void freeconnection (string name, connection con) {
DBConnectionPool Pool = (dbconnectionpool) pools.get (name);
IF (pool! = null) {
Pool.FreeConnection (con);
}
}
Third, close
Finally, a Release () method is used to close the connection pool. Each DBConnectionManager customer must call the getInstance () method reference. There is a counter to track the number of customers. Method Release () calls when the customer is turned off, and the technique minus 1. When the last customer is released, DBConnectionManager closes all connect pools.
List 11-14
Public synchronized void release () {
// Wait Until Called by the Last Client
IF (--Clients! = 0) {
Return;
}
Enumeration allpools = pools.ements ();
While (allpools.hasmorelements ()) {
DBConnectionPool Pool = (dbconnectionpool) Allpools.nexTelement ();
pool.release ();
}
Enumeration alldrivers = drivers.ements ();
While (alldrivers.hasmorelements ()) {
Driver driver = (driver) alldrivers.nextelement ();
Try {
Drivermanager.deregisterDriver (driver);
LOG ("Deregistered JDBC Driver Driver.getClass (). getname ());
}
Catch (SQLException E) {
LOG (E, "Can Not Deregister JDBC Driver:"
Driver.getClass (). getname ());
}
}
}
All JDBC drivers are also logged out when all connecting pools are closed.