This article will tell you about how web developers can provide a strategy for applications that must handle connection pooling. This document will give an overview of JDBC connection pooling as specified by the JDBC 3.0 specification. This Connection Pool Manager is shipped with DataDirect Connect® for JDBC and DataDirect SequeLink® for JDBC. Finally, this document provides an example showing performance benchmarks that demonstrate the performance benefit by using connection pooling.
Connection Pooling
On the other side, establishing JDBC connections can be resource-expensive. Especially, when the JDBC API is used in a middle-tier server environment, or when DataDirect Connect for JDBC or DataDirect SequeLink for JDBC is running on a Java-enabled web server. In this condition, when connection pooling is used performance can be improved significantly. Rather than created connections each time a connection is requested, connection will be reused in Connection pooling. A connection pool works by a connection pooling module as a layer on top of any standard JDBC driver product.
Connection pooling will not affect how an application is coded as it will be performed in the background. However, the application must use a DataSource object (an object implementing the DataSource interface) in order to obtain a connection instead of using the DriverManager class. A class implementing the DataSource interface may or may not provide connection pooling. A DataSource object registers with a JNDI naming service. After a DataSource object is registered the application will retrieve it in the standard way from the JNDI naming service.
For example:
Context ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup(“jdbc/SequeLink”);
The lookup returns a connection from the pool if one is available, if the DataSource object provides connection pooling. However, if there is no connection pooling or if there are no available connections in the pool, the lookup creates a new connection. The application will get advantages from connection reuse without the need to change any code. In fact, reused connections from the pool act the same way as newly created physical connections. Connection to the database and data access works in the usual way with the application. Furthermore, the application explicitly closes the connection, when the application has finished its work with the connection.
For example:
Connection con = ds.getConnection(“scott”, “tiger”);
// Do some database activities using the connection…
con.close();
For future reuse, the pooling module will get signal from the closing event on a pooled connection signals to place the connection back in the connection pool.