When executing the database SQL statement, we must first perform data connections; and each time you create a new database is consumed to consume a lot of resources, so everyone comes to the database connection pool technology. Its principle is that during the run, a certain number of database connections are turned on, form a data connection pool, and take a connection from it, after the data connection is required, after the Some SQL operation, the system is automatically recycled, Other users (or processes) calls.
We know that Java standard java.sql.connection represents a data connection. We encapsulate this class to form your own database connection pool. To illustrate convenience, here is used in the actual class:
DBConnectionPool Real Data Connection Pool
DBConnectionManager is managing multiple pools
The relationship is as follows:
Actual implementation process:
1) Creating an instance of a DBCONNECTIONMANAGER class.
2) Then call DBConnectionManager. CreatePool () Create a connection pool and add this connection pool to the Pools's HastHtable. (This process can be performed multiple times, corresponding to different data connections, may be SQL2K, or Oracle, but generated DBConnectionPool is put in Pools to do unified management, use and use a name to correspond to the corresponding dbconnectionPool ).
3) When a data connection is required, you first get a DBConnectionPool, then you can see if there is an idle connection from DBConnectionPool, if any, use. If not, there is no maximum number of connections, create a Connection connection and returns this.
4) If a connection is used, call DBConnectionManager.freeConnection (String Name, Connection CON), which calls dbconnectionPool. FreeConnection (Connection Con), this point, connection is not truly released, but this temporarily unused Connection Put it in the FreeConnections array of DBConnectionPool, while notifying the other threads waiting for the connection. In this way, when you use it, you don't have to create a new Connection.