Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / March 2004

Tip: Looking for answers? Try searching our database.

finding connection leaks

Thread view: 
Jochen Reitzig - 09 Mar 2004 00:02 GMT
Hello!

Can anybody recommend a tool that can scan Java code for unclosed
connections. In this specific case I am dealing with pretty messy code
inherited from the predecessor that requires a clean up due to
increasing performance problems.
We have observed that after a certain uptime we have thousands of
sleeping connections to the database. The easiest thing that this tool
e.g. would have to do is to scan the code for missing finally{}
statements in which you usually close connections.

Any recommendation and advise is highly appreciated. Thanks, Jochen

P.S. RSVP to the news group or rephrase the email address properly. Thx

Signature

Jochen Reitzig
+1-408-718-1174
mailto: jochen.reitzig_Place_AT_here_web.de
San Jose, CA

Joe Fischer - 09 Mar 2004 01:26 GMT
>Hello!
>
[quoted text clipped - 10 lines]
>
>P.S. RSVP to the news group or rephrase the email address properly. Thx
    First thought would be to wrap the connections into a
connection pool that could periodically scan for dead connections and
recycle them.
-------
Remove underscores from e-mail address.
Joe Weinstein - 09 Mar 2004 02:47 GMT
> Hello!
>
[quoted text clipped - 8 lines]
>
> Any recommendation and advise is highly appreciated. Thanks, Jochen

I would decompile the JDBC driver's connection class, and alter it to
record a stacktrace of where is is created, then recompile that class as
a diagnostic patch. I would add a finalize() method (or augment the current
one), to check whether the connection had been closed. If it had not been
closed by the time it is being GC'ed, I would print out a message saying:
A JDBC connection was abandoned without being closed. It was created at...
(print the creation stack trace). The saved stacktrace will show you where
in the application the connection was created, and you can alter that code
to do the close.

Joe Weinstein at BEA
Jochen Reitzig - 10 Mar 2004 03:28 GMT
Hi Joe,

we have already done something shooting into this direction. Whenever we
open the connection we add some log  entry and also add an associated
log entry when we purposely close the connection.
This, however is a quite a chunk of work as we are dealing with a huge
code base. I have read  a while ago about tools that detect e.g. not
released memory in C and C++ code. I have no practice experience but I
would guess that there is a similar QA tool for Java. Thank you, Jochen

> I would decompile the JDBC driver's connection class, and alter it to
> record a stacktrace of where is is created, then recompile that class as
[quoted text clipped - 7 lines]
>
> Joe Weinstein at BEA

Signature

Jochen Reitzig
+1-408-718-1174
mailto: jochen.reitzig_Place_AT_here_web.de
San Jose, CA

Robert Klemme - 10 Mar 2004 07:46 GMT
> Hi Joe,

I'd say the correct spelling is "Hey Joe" as in
http://www.daily-lyrics-4all.com/Hey_Joe_Lyrics.html
:-)

> we have already done something shooting into this direction. Whenever we
> open the connection we add some log  entry and also add an associated
[quoted text clipped - 3 lines]
> released memory in C and C++ code. I have no practice experience but I
> would guess that there is a similar QA tool for Java. Thank you, Jochen

Optimizeit does a quite good job at detecting leaks.  The only problem
with these memory analyzers is that they have to process a huge amount of
data in a typical appliaction which may or may not work depending on the
resources of your machine.

Then there's JMP which I didn't use yet:
http://www.khelekore.org/jmp/

I'd like to add two other options:

(i) Trace program execution.  Here are some options:

http://alfj.sourceforge.net/
http://www.geocities.com/mcphailmj/Trace/
http://www.experimentalstuff.com/Technologies/TracingJVM/index.html

(ii) Wrap the whole JDBC layer with your own classes that delegate to the
real drivers classes and emit some interesting diagnostic information.
The downside is that this is quite tedious since there are quite some
classes to be implemented if you want to do it completely.  In your case,
Connection and some of the Statement derivates might suffice.

Kind regards

   robert
Tanel Lebedev - 09 Mar 2004 10:07 GMT
> Hello!
>
[quoted text clipped - 10 lines]
>
> P.S. RSVP to the news group or rephrase the email address properly. Thx

Maybe you should look for a more radical solution, for example
http://weblogs.java.net/pub/wlg/1092


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.