commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rodney Waldhoff <>
Subject Re: DBCP tracking stale connections?
Date Mon, 09 Dec 2002 13:05:24 GMT

On Mon, 9 Dec 2002, Tim Funk wrote:

> DBCP can close connections if they have been opened to long by a client.

This is correct.

> The close check is issued only when another request to obtain a
> connection is made.

This isn't quite correct.  In fact, I think these "idle time" checks
only run asynchronously.

Assuming you're using a GenericObjectPool based DBCP, you can do this:

a) Set the "minEvictableIdleTimeMillis" property.  This determines how
long an object can idle in the pool before we may evict it.

b) configure an "eviction thread", by setting the
timeBetweenEvictionRunsMillis property (or periodically invoking evict()
on your own)

> As for testing for stale connections - there is a parameter when DBCP
> pools are created that allow you to specify a query to check a
> connections health. If the query fails  - then the connection is
> considered bad and DBCP will discard the connection and open a new one.

Right, specifically, set the validationQuery property of your
PoolableConnectionFactory, and set one (or more) of testOnBorrow,
testOnReturn or testWhileIdle to true. (The BasicDataSource bundle will
automatically set testOnBorrow to true when a validationQuery is set.)

I think this topic has been discussed a few times on the user or dev list
or both, you may want to search the archives (e.g., for more.)

> Martin van Dijken wrote:
> > Hey gang,
> >
> > I know I should ask this question on users, but bear with me a second. Does DBCP
track and terminate connections which have been idle so long that they are killed by the DBMS?
> >
> > The reason I ask, is that after 8 hours of inactivity on a website(and thus DBconnections)
mysql considers connections to be lost and kills them. After that the website fails to work.
All connections throw IOExceptions telling me that no connection could be established.
> >
> > Love to hear from ya,
> >
> > Martin van Dijken
> >
> --
> To unsubscribe, e-mail:   <>
> For additional commands, e-mail: <>

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message