You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Martin van Dijken <mv...@madocke.nl> on 2002/12/09 11:11:30 UTC

DBCP tracking stale connections?

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

Re: DBCP tracking stale connections?

Posted by Jacek Laskowski <ja...@hp.com>.
Tim Funk wrote:
> DBCP can close connections if they have been opened to long by a client. 
> The close check is issued only when another request to obtain a 
> connection is made.
> 
> 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.
> 

Hi Tim,

Unfortunatelly, it doesn't work for BasicDataSource, which may have been 
used by Tomcat internally, but only for Jdbc2PoolDS, which I haven't yet 
gave it a try. According to javadoc, moving from BasicDS to Jdbc2PoolDS 
should not incur any problems.

Anyone's tested DBCP in this regard ?

-Jacek


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: DBCP tracking stale connections?

Posted by Rodney Waldhoff <rw...@apache.org>.

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.,
http://archives.apache.org/ 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:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: DBCP tracking stale connections?

Posted by Tim Funk <fu...@joedog.org>.
DBCP can close connections if they have been opened to long by a client. 
The close check is issued only when another request to obtain a 
connection is made.

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.

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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>