skip to main content
Getting Started : Advanced Features : Using Connection Pooling : Understanding Connection Pooling
  
Understanding Connection Pooling
A connection pool implementation, such as the DataDirect Connection Pool Manager, creates database connections, referred to as PooledConnections, using the getPooledConnection() method of the ConnectionPoolDataSource interface. Then, the Pool Manager registers itself as a listener to the PooledConnection. When a client application requests a connection, the Pool Manager assigns an available connection. If a connection is unavailable, the Pool Manager establishes a new connection and assigns it to that application.
When the application closes the connection, the Pool Manager is notified by the driver by the ConnectionEventListener interface that the connection is free and available for reuse. The Pool Manager is also notified by the ConnectionEventListener interface if the database connection is corrupted so that the Pool Manager can remove that connection from the pool.
Connection pool implementations, such as the DataDirect Connection Pool Manager, use objects that implement the javax.sql.ConnectionPoolDataSource interface to create the connections managed in the pool. All DataDirect Connect Series for JDBC DataSource objects implement the ConnectionPoolDataSource interface.
Once a data source has been created and registered with JNDI, it can be used by your JDBC application as shown in the following example, typically through a third-party connection pool tool:
Context ctx = new InitialContext();
ConnectionPoolDataSource ds =
(ConnectionPoolDataSource)ctx.lookup("EmployeeDB");
Connection conn = ds.getConnection("scott", "tiger");
In this example, first, the JNDI environment is initialized. Next, the initial naming context is used to find the logical name of the JDBC data source (EmployeeDB). The Context.lookup method returns a reference to a Java object, which is narrowed to a javax.sql.ConnectionPoolDataSource object. Next, the ConnectionPoolDataSource.getPooledConnection() method is called to establish a connection with the underlying database. Finally, the application obtains a connection from the ConnectionPoolDataSource.
The DataDirect Connection Pool Manager is shipped with the product. Refer to "Connection Pool Manager" in the DataDirect Connect Series for JDBC Reference for more information about managing connection pools using the DataDirect Connection Pool Manager.