Connection pool:create many Connection objects in advance, and put the Connection into the cache (list). The client would get the connection from the cache, and return the Connectio to the cache after using it. This is the could improve the access effeciency of data base.
Simulate the connection pool:
PackageCom.pp.pool;Importjava.sql.Connection;Importjava.util.ArrayList;Importjava.util.List;ImportCom.pp.util.JdbcUtil;/** Simulate the completion of Connetion pool*/ Public classSimpleconnectionpool {Private StaticList<connection> pool =NewArraylist<connection>(); Static { for(inti = 0; I < 10; i++) {Connection conn=jdbcutil.getconnection (); POOL.ADD (conn); } } //get the Connection object from the cache pool Public synchronized StaticConnection getconnection () {if(Pool.size () > 0) {Connection conn= Pool.remove (0); returnConn; } Else { Throw NewRuntimeException ("Server is busy!"); } } //Return the connection Public Static voidReleas (Connection conn) {POOL.ADD (conn); }}
JDBC--Connection Pool