I recently came across some feedback on some code that I wrote that mentioned I had issues with connection leaks. From what I understand, a connection leak is when you don't close a connection after you have opened it. Is this correct?
An pseudo - code example of what I was doing that caused this feedback to occur is something like the following:
DbUtils - a class that handles the closing of a connection.
DatabaseInfo = a class that holds connection data.
The methods loadSomeData and loadSomeMoreData are private methods that simply open statements and result sets, then close them in a finally block. They then throw any exceptions that occur.
I understand this is a bit abstract, and I will write up a more detailed example if need be. Thanks guys.
It is returned to the pool when you call the close() method.
Charles Owen wrote:... If you are using any sort of Connection Pooling, setting the Connection object to null returns the connection back to the Connection Pool so it can be reused. ...
(although Sun says
When a Context instance is done with a connection (closed or garbage collected), the connection is returned to the pool for future use.
the Java community typically uses close() to return connections.
I would advise you to do the same. When you call close(), the connection is immediately returned to the pool. That is predictable behavior. Can you predict how/when/if the garbage collector handles it?)
Charles Owen wrote: I am no longer going to post in these forums. I have a lot to learn.
It's ok to post even if you aren't sure of something. You can say "I think". That way if you are wrong someone will jump in. And you learn something either way!
I've posted things that I wasn't sure of with "I think" along with a few things that were flat out wrong. (such as when I was tired or misinterpreted the question) I was corrected. Not a big deal.
Charles. I did not try to make you look like an idiot. This was my attempt to post a polite reply.
Charles Owen wrote:You're right, I'm an idiot.
I learned my lesson. I am no longer going to post in these forums. I have a lot to learn. Thanks for correcting it.
My excuses if I offended you.