It's extremely unlikely that the GC will ever even see that connection
-- because the pool is still aware of it (it knows you checked it
out), so it probably will never be collected.  It's way better for you
to make sure you close your result sets, statements and connections in
a finally block.  Calling close() is how pools know you're done with
the connection.

DBCP (and other pools) have support for finding connections that have
been checked out of the pool but never returned, but you should never
rely on this for "normal" use.

If you don't/can't make sure to close those connections, consider
using a framework like iBatis or Spring JDBC Template, which take care
of all that stuff for you.  They are not as heavy as Hibernate, and
take care of just the annoying details like making sure you close
connections.

-nate



"The sky calls to us. If we do not destroy ourselves, we will one day
venture to the stars." -- Carl Sagan




On Tue, Jun 5, 2012 at 2:03 AM, Ryan How <[email protected]> wrote:
> Hi,
>
> I was having a quick look through the source of JdbcConnectionPool, but I
> was unable to determine if connections are automatically returned to the
> pool if close is not called.
>
> So if I don't call close on the connection, and the thread with the
> connection ends, will the garbage collector automatically return it to the
> pool when it feels like it?
>
> If it doesn't I might want to put a safety on the connection pool so
> accidentally not calling close doesn't take down the whole application
> eventually...
>
> Thanks, Ryan
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "H2 Database" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/h2-database?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/h2-database?hl=en.

Reply via email to