Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check the Database Connection leakage in Java EE application?

Is there any way to check the connection leakage in a Java EE application?

The application is running on my local machine. It uses a MySQL database and a user enters his details into this database.

In my opinion connection leakage means not closing the connection object properly. I am creating too many database connections in my application. I want to check if there is any connection leakage in the database connections.

like image 810
Puru Avatar asked Jun 19 '10 12:06

Puru


2 Answers

log4jdbc, a Java JDBC driver that can log SQL and/or JDBC calls for other JDBC drivers, has a logger which logs connection open and close events as well as dumping all open connection numbers. This is very useful for hunting down connection leak problems.

Another tool that you might want to check is ConnLeakFinder, a simple tool to pinpoint jdbc connection leaks in java code. I don't have any experience with it though.

like image 180
Pascal Thivent Avatar answered Oct 26 '22 14:10

Pascal Thivent


If you're using a Java EE app server, you should be able to configure it to check connections when they go out and reclaim stale connections when they don't come back.

Connection leakage is indeed a problem. I'd be worried if you had connection management scattered in so many places in the code that it was a big problem to find them all. I'd expect to see a Java EE connection pool that was used only within a well-defined persistence layer. Connections should be opened by a service layer that manages the transaction for that unit of work and closes it as soon as the use case is over, within method scope in a finally block.

If that's not true, I think it's time to refactor.

like image 41
duffymo Avatar answered Oct 26 '22 14:10

duffymo