Breaking News
Home / Java / Java Tutorials / What is Database Connection Pool Leak?

What is Database Connection Pool Leak?

Connection Pool LeakConnection Pool help to increase the performance by keep active connections to the database in the pool. The pool is normally managed by the Pool Manager. The Client (API) is supposed to borrow a connection from the pool, execute the sql query or updates and finally return back the connection to the pool. However if the connection object is not returned back to the pool, the pool will have one less connection than it should have. This is called a Connection Pool Leak. Eventually if this keep on happening the pool will be out of connections, this is called Pool Exhaustion. 

 

Pool Manager connection Leak

Normally this happens if the programmers forgets to invoke the return connection method or under some conditions the return connection method is not invoked.

Certain applications servers can detect whether there is a connection leak. For example Weblogic Server 8.x gives out warning in the logs when such scenario occurs.

<Feb 17, 2010 4:29:02 AM PST> <Warning> <JDBC> <BEA-001074> <A JDBC pool connection leak was detected. A connection leak occurs when a connection obtained from the pool was
not closed explicitly by calling close() and then was disposed by the garbage collector and returned to the connection pool. The following stack trace at create shows wher
e the leaked connection was created.  Stack trace at connection create:

        at weblogic.jdbc.wrapper.JTSConnection.initCopy(JTSConnection.java:201)
at weblogic.jdbc.jts.Driver.copyConnection(Driver.java:277)
at weblogic.jdbc.jts.Driver.copyLocalConnection(Driver.java:257)
at weblogic.jdbc.jts.Driver.connect(Driver.java:147)
at weblogic.jdbc.common.internal.RmiDataSource.getConnection(RmiDataSource.java:305)
…….

In order to find the leak, do a through code review. Make sure the connection is returned back to the pool. Also make sure all the relevant objects like PreparedStatments and ResultSet are closed. Have the cleanup of the all these objects in the finally block to be sure as shown below.

      try {
 borrowConnection();
executeSQLQueryOrUpdate();

} catch (Exception e) {

} finally {
try {
 rst.close();
} catch (SQLException e) {
log.warn(“Failed to close the Recordset” + e, e);
}

try {
 ps.close();
} catch (SQLException e) {
log.warn(“Failed to close the Prepared Statement” + e, e);
}

try {
// Return the Connection
 returnConnection();
} catch (SQLException e) {
log.warn(“Failed to return the Connection” + e, e);
}
}

 

[pb_builder]

Check Also

Missing license file for: WebLogic Platform 8.1

Issue java.lang.RuntimeException: Missing license file for: WebLogic Platform 8.1         at weblogic.security.utils.SSLSetup.getLicenseLevel(SSLSetup.java:157)         at weblogic.security.utils.SSLSetup.getWrapperClass(SSLSetup.java:195) …

  • shivam

    can we get back the leaked connection through weblogic?

Advertisment ad adsense adlogger