Connection Pooling

A connection pool is used to manage a pool of database connections. By reusing existing connections from a pool rather than creating new connections, connection pools reduce the overhead associated with establishing new connections.

The Java API offers built-in support for connection pooling. In scenarios where connection objects are frequently created and destroyed, using a connection pool can significantly reduce the costs associated with these operations, thereby improving program efficiency and simplifying connection management.

The primary purpose of a connection pool is to manage multiple connections efficiently by using pooling techniques. Instead of creating and destroying connection objects repeatedly, a connection pool maintains a set of connections that can be reused for different tasks. This leads to the following benefits:

  • Reduced Cost: Creating and destroying connection objects is expensive. Using a connection pool minimizes these costs by reusing existing connections.
  • Improved Efficiency: Since connections are reused, the overhead associated with establishing a new connection is avoided, leading to better performance.
  • Simplified Management: The connection pool manages the life cycle of connections, relieving users from the burden of manually handling connection creation and destruction.

Connection pools are particularly useful in scenarios where:

  • Java code involves many connection objects.
  • Managing connection objects is complex.
  • Connection objects need to be frequently created and destroyed.

Java API provides two types of connection pools SimpleDBConnectionPool and ExclusiveDBConnectionPool, which will be introduced in the following sections.