JDBC Connection pool framework
in enterprise database applications, the database connection pool (Connection pool) is a very important component. The primary function of the connection pool is to manage and control several types of resources in JDBC (connection,statement,resultset) to provide high-performance database access while preventing the unrestricted use of these types of resources, resulting in performance degradation and even service crashes. Connection pool generally has the maximum number of connections, the minimum number of connections, the maximum number of concurrent connections and other attributes. Before JDBC3.0 the connection pool framework, some application servers and database vendors provided their own connection pooling components, and customers might have different configurations when using different connection pooling services. The JDBC3.0 specification defines the framework for a standard connection pool and several standard attributes.
The
JDBC Connection pool API
pooledconnection represents a physical connection to the data source. It is managed by ConnectionPoolDataSource and can be reused. In contrast, the connection we use every day is called a logical connection.
connectionpooldatasource Connection pool data source, which manages the Pooledconnection factory.
ConnectionEvent The event that is generated when a pooledconnection connection is closed, or when an error occurs. The
Connectioneventlistener connectionevent event listener.
The above APIs are oriented to application servers and JDBC drivers, and unless you are implementing your own connection pool, applications that use JDBC generally will not and should not deal with these interfaces, or face standard datasource,connection interfaces. When our application invokes the DataSource getconnection () method to obtain connection, it actually obtains a poolconnection handle from the connection pool. The actual poolconnection may be already existing in the connection pool, or it may be newly created, and the application will not know. When the close () method of the connection is invoked, only the logical connection is closed, and the actual poolconnection is returned to the pool for reuse.
Open source Connection pool implementation
currently has a large number of open source connection pool implementations, most of them are relatively independent components, through a certain configuration can be used in our applications. Here are three more used connection pools:
DBCP It is the database connection pool that has been brought up in Tomcat.
c3p0 It is a database connection pool developed along with Hibernate.
Proxool It is a JAVA SQL driver driver that provides a variety of JDBC-driven connection pooling packages.
The above several connection pool configuration method is very similar, each has its own strengths, can be based on specific applications and a variety of evaluation data to choose.