What is Connection Pooling leak?

Connection Pooling Leakage problem
Connection Pooling Leakage problem

Database connection Pooling leaks can occur if you don't close database connections in a proper way or you can say when a connection is opened, forgot to close This is known as a "Connection Pooling leak".This problem is occurring by most of time Developer side. Using a Connection Be aware of the Leak problem.

Stop Connection Pooling  Leaks?

There are plenty of Tools and jar which can help you to Stop Connection Pooling  Leaks. But using any tools will increase your time and effort for you. So how to Detect the Connection Pooling  Leaks and Stop them.

Finding or Detect Connection Pooling  Leaks.

1)The most simple and Easy way to find Connection Pooling leaks is to search in every page that connection is closed properly or not but this approach is too hard
if the application is a huge one.

2)The second one is commenting your connection method your connection class is there comment the getConnection method or else what you have written for getting connection comment that method and then there you see the error in all page where you used the connection Pooling connection. Hence you can easily find is there any page you forget too close the connection.

3)The Third one is most used and simple to Trace or detect or find the Connection leakThe simple approach in connection class declared a static variable like
public static int count=0; if connection used it will make count as increment by ++count and if connection close make count as decrement by --count.
When you do such thing when everwhere connection Pooling connection is open count will one and when connection Pooling connection close it will became zero. Always count will zero if you close connection Pooling connection properly check every page you will find it. How to Close Connection Properly.

This Code of Pooling connection class

public class ConnectionManager {
  public static int connectionCount = 0;

  public static Connection getConnectionFromPool() {
         Connection con = null;
         try {
             con = Yourconnection method.getConnection();
             ++connectionCount ;
    System.out.println("Connection Open Count ......" + connectionCount);
         } catch (Exception ex) {
             log.error(ex);
         }
         return con;
     }

  public static void closeConnection(Connection con) {
         try {
             if (con != null) {
                 con.close();
                 connectionCount --;
                 con = null;
                 System.out.println("Connection Close  Count ...... " + connectionCount);
             }
      
         } catch (Exception e) {
         }
As you can see we have taken connectionCount int static variable for the for checking the connection open and close. Whenever Connection is open we print Connection Open Count++ and if the same connection close then we print Connection Close  Count--.This is simple any easy way to detect the connection leaks in java.
If you want to know how to Properly close the connection then click.

Connection leak
Connection leak

Previous Post Next Post