• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

DB Connection object tracking

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

How can a DB connection object created by DataSource.getConnection() be tracked.
i.e., How to make sure the receiver of the connection is closing it properly or not.

Let's assume i'm exposing a method that returns the connection object(created by datasource lookup followed by datasource.getConnection()) to the caller which the caller can use to perform some DB operations.

If the above method is used in multiple places, how can one make sure that the callers are closing the connection or not ?
Since DataSource is a managed object , Can we count/track the connection leaks ?

Thanks.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to JDBC.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Off the top of my head, unless there was a timeout for holding on to a connection, I don't see how-how would you distinguish between a process that had a connection, legitimately, versus a process that just forgot to close the connection? Perhaps if you tracked the entries and exits of those processes, with filters/AOP advice/etc, butnthen why not just delegate the opening and closing of connections to those?

I guess that's why they invented the many ways to make things transactional, so you wouldn't have to worry about such things.
 
Raga Baskaran
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for responding.
Yes i can track the entries and exits of the processes using AOP/advise which calls my method. But my idea here to write a JSP to find out the open connections at any given instant ordered by connection creation time in descending order.
This page will display the caller class & method and the connection creation time, and this can help me in determining the leaks.

Since datasource is a container managed object, Does the container provide a way to view such info or a similar tool in admin console to see ?

Thanks.
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch , Raga Baskaran
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Decorator pattern. Extend the datasource type, override the getConnection and close methods to add logging then call the superclass. Note you may need to package your class somewhere the server can see it or you'll have visibility issues. That is if you declare the datasource in your server then the code will need to be in with the server common code.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic