Loading...
четвер, 18 липня 2013 р.

Detect leak DB connections

How to detect leak connections to database in Java? Of course, one can use particular monitoring tools like  Zabbix, but there is one more way. 
There is an utility, called ConnLeakFinder, just a wrapper for general JDBC connection. So usage of this is simple: just find where connection is established (code like following)

//Load JDBC driver
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn  = DriverManager.getConnection( CONNECTION_PARAMETERS);
return conn;

and add wrapper before return statement:
try{
     //Wrap connection with connleakfinder
     conn = new ro.kifs.diagnostic.Connection(conn);
}
catch(Exception e){
      //Some error message here
      e.printStackTrace();
}

Now you can use following method to get connections, that remain unclosed:
ro.kifs.diagnostic.Connection.getStillOpenedConnsStackTraces();

0 коментарі:

 
TOP