Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can i track unclosed connection in my code ?

 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hello please suggest your ideas on

How can i track connection which are not closed on to a Application. (so that instead of worrying about memory leak later )

Waiting for your suggestions and ideas on this .
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34095
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use a monitoring tool to check it at runtime or a static analysis tool to find some cases at build time.
 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please tell the names of those tools .(except Jamon as its learning curve is high)
 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
will FindBugs suit for this requirement ?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34095
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
RaviNada,
I've never needed a tool to do this as I use a framework that handles closing resources for me. It would be equal effort to go through the tools (google the categories I listed) to find out which ones support your requirement. Or maybe you'll be lucky and someone who sees this Monday will have had the same requirement as you and knows the solution off the top of their head.

For FindBugs, you already know the name of the tool making it easy to find this information. FindBugs has the list of rules online. The ODR ones look like what you need.
 
Moojid Hamid
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can subclass the "connection" and keep a count of open connections, you will have to make sure that only the subclass is being used in the application.
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure you will get a solution any easier than jamon.

- Connect to the database with the jamon jdbc proxy driver
- install the war to view the jdbc/sql stats.

If you have specific questions feel free to ask follow up questions. Here is a link that shows how to connect with the jamon proxy driver. http://jamonapi.sourceforge.net/#WhatsNew22

 
Tim Holloway
Saloon Keeper
Pie
Posts: 18012
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Apache dbcp connection pooler can be configured to take a stack snapshot when you acquire a connection. The snapshot is then saved, and if you end up with leaks, it can be dumped, so you'll know where it was opened.

However, the ability to ensure that connections don't leak is one of the primary reasons I use the Spring Framework to manage my persistency layers. I've seen too much hand-written code that forgot to free up stuff when an unexpected SQL exception was thrown.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic