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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With