> This is a bit off topic.

Par for the course lately :)

> I am using connection pooling, and in my code, I open all the connection I
> need in an object constructor.
> Then I will close this connection in finalize(), which (according
> to what I
> read) will be executed during java garbage collect.

The finalize method will be called, but there's no way to determine when.

<snip>

>
> Would this be okay? is it guaranteed that finalize() will be
> executed during
> garbage collect??

You could do this, but its really really bad practice.  If you're going to
be using connection pooling the issue is, usually, that you don't enough
connections.  Assuming you have a connection pool that has say 3
connections, w/o a soft limit, you're going to run out of connections after
using this object 3 times.  You can't say when the garbage collector is
going to actually call the finalize method, so you can't determine when the
connection will be closed.  So you're going to be out of connections and
probably blocked waiting for connections until an object is finalized.  If
you have a large amount of memory allocated to tomcat you'll be waiting a
long time for that finalize method.

The best practice is to check out the connection when you need it and return
it after you finish working with it.  Preferably in a try->catch->finally
block.  Anything else and you run the risk of loosing connections acquired
from the pool, again exhausting the available connections.

--mikej
-=-----
mike jackson
[EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to