You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Johannes Lietz <jo...@antwerpes.de> on 2003/06/24 18:18:13 UTC

[DBCP] Testing of connections

I've got the following problem:

I'm using DBCP from inside Tomcat to connect to a database. Between 
Tomcat and database server is a firewall.

And this firewall is causing problems: when a database connection is 
idle for some time, the firewall will block this connection, and not 
drop the connection.

Therefore DBCP thinks the connection is still open and alive and tries 
to use it. And as the connection is blocked, DBCP will wait eternally 
until something happens.


My question: Is there any way to configure DBCP to test connections 
regularly and refresh them if necessary? Or to set a timeout when a 
connection is declared dead and dropped?

Thanks,
Johannes


Re: [DBCP] Testing of connections

Posted by Rodney Waldhoff <rw...@apache.org>.
On Wed, 25 Jun 2003, Serge Knystautas wrote:

> Yes, the current release has only one validation query spot, which as
> you say is during testOnBorrow.

No.  The current release, indeed the initial import of the source into
commons, has one validation query and three places it can be used,
independently or in combination.  There are 8 possible combinations
available--on borrow, on return, when idle, each independently on or off.

>
> This will still cause your firewall to kill connections, and then DBCP
> will validate the connection, find it's bad, and get a good connection
> for your app.  (For me this is preferrable to keeping idle connections
> open just because of a periodic validation check.)

Independent of the validation/keep-alive query, you can tell the pool to
evict connections that have been idle for too long.  Set
minEvictableIdleTimeMillis and timeBetweenEvictionRunsMillis.

- Rod <http://radio.weblogs.com/0122027/>

>
> --
> Serge Knystautas
> President
> Lokitech >> software . strategy . design >> http://www.lokitech.com
> p. 301.656.5501
> e. sergek@lokitech.com

Re: [DBCP] Testing of connections

Posted by Serge Knystautas <se...@lokitech.com>.
Yes, the current release has only one validation query spot, which as 
you say is during testOnBorrow.

This will still cause your firewall to kill connections, and then DBCP 
will validate the connection, find it's bad, and get a good connection 
for your app.  (For me this is preferrable to keeping idle connections 
open just because of a periodic validation check.)

-- 
Serge Knystautas
President
Lokitech >> software . strategy . design >> http://www.lokitech.com
p. 301.656.5501
e. sergek@lokitech.com

Johannes Lietz wrote:
> Thanks, this is what I'm looking for.
> 
> But if I understand the documentation/source correctly these are 
> features of the upcoming 2.0 release? If so I guess this is nothing I 
> would like to use in a production enviroment soon... :-(
> 
> Or is setting a validationQuery (which apparently causes some 
> "testOnBorrow") in 1.0 sufficient?


Re: [DBCP] Testing of connections

Posted by Johannes Lietz <jo...@antwerpes.de>.
Thanks, this is what I'm looking for.

But if I understand the documentation/source correctly these are 
features of the upcoming 2.0 release? If so I guess this is nothing I 
would like to use in a production enviroment soon... :-(

Or is setting a validationQuery (which apparently causes some 
"testOnBorrow") in 1.0 sufficient?

- Johannes



On Dienstag, Juni 24, 2003, at 06:31  Uhr, Rodney Waldhoff wrote:

> You can add a SQL statement to verify the connection after each use 
> (set a
> validation query and set testOnReturn to true), before each use (set a
> validation query and set testOnBorrow to true), or between use (set a
> validation query, a testing period, and testWhileIdle to true), or any
> combination of these.
>
> I think the latter case--testing when idle--is what you want here.  It
> will periodically use the connection if your app isn't otherwise using 
> it,
> which will keep the firewall and/or database from timing it out.
>
> - Rod <http://radio.weblogs.com/0122027/>
>
> On Tue, 24 Jun 2003, Serge Knystautas wrote:
>
>> There actually has just been some recent discussion on how to handle
>> this better.
>>
>> For now, you can add a SQL statement to verify the connection after 
>> each
>> use.
>>
>> --
>> Serge Knystautas
>> President
>> Lokitech >> software . strategy . design >> http://www.lokitech.com
>> p. 301.656.5501
>> e. sergek@lokitech.com
>>
>> Johannes Lietz wrote:
>>
>>> I've got the following problem:
>>>
>>> I'm using DBCP from inside Tomcat to connect to a database. Between
>>> Tomcat and database server is a firewall.
>>>
>>> And this firewall is causing problems: when a database connection is
>>> idle for some time, the firewall will block this connection, and not
>>> drop the connection.
>>>
>>> Therefore DBCP thinks the connection is still open and alive and 
>>> tries
>>> to use it. And as the connection is blocked, DBCP will wait eternally
>>> until something happens.
>>>
>>>
>>> My question: Is there any way to configure DBCP to test connections
>>> regularly and refresh them if necessary? Or to set a timeout when a
>>> connection is declared dead and dropped?
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>


Re: [DBCP] Testing of connections

Posted by Rodney Waldhoff <rw...@apache.org>.
You can add a SQL statement to verify the connection after each use (set a
validation query and set testOnReturn to true), before each use (set a
validation query and set testOnBorrow to true), or between use (set a
validation query, a testing period, and testWhileIdle to true), or any
combination of these.

I think the latter case--testing when idle--is what you want here.  It
will periodically use the connection if your app isn't otherwise using it,
which will keep the firewall and/or database from timing it out.

- Rod <http://radio.weblogs.com/0122027/>

On Tue, 24 Jun 2003, Serge Knystautas wrote:

> There actually has just been some recent discussion on how to handle
> this better.
>
> For now, you can add a SQL statement to verify the connection after each
> use.
>
> --
> Serge Knystautas
> President
> Lokitech >> software . strategy . design >> http://www.lokitech.com
> p. 301.656.5501
> e. sergek@lokitech.com
>
> Johannes Lietz wrote:
>
> > I've got the following problem:
> >
> > I'm using DBCP from inside Tomcat to connect to a database. Between
> > Tomcat and database server is a firewall.
> >
> > And this firewall is causing problems: when a database connection is
> > idle for some time, the firewall will block this connection, and not
> > drop the connection.
> >
> > Therefore DBCP thinks the connection is still open and alive and tries
> > to use it. And as the connection is blocked, DBCP will wait eternally
> > until something happens.
> >
> >
> > My question: Is there any way to configure DBCP to test connections
> > regularly and refresh them if necessary? Or to set a timeout when a
> > connection is declared dead and dropped?
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>

Re: [DBCP] Testing of connections

Posted by Serge Knystautas <se...@lokitech.com>.
There actually has just been some recent discussion on how to handle 
this better.

For now, you can add a SQL statement to verify the connection after each 
use.

-- 
Serge Knystautas
President
Lokitech >> software . strategy . design >> http://www.lokitech.com
p. 301.656.5501
e. sergek@lokitech.com

Johannes Lietz wrote:

> I've got the following problem:
> 
> I'm using DBCP from inside Tomcat to connect to a database. Between 
> Tomcat and database server is a firewall.
> 
> And this firewall is causing problems: when a database connection is 
> idle for some time, the firewall will block this connection, and not 
> drop the connection.
> 
> Therefore DBCP thinks the connection is still open and alive and tries 
> to use it. And as the connection is blocked, DBCP will wait eternally 
> until something happens.
> 
> 
> My question: Is there any way to configure DBCP to test connections 
> regularly and refresh them if necessary? Or to set a timeout when a 
> connection is declared dead and dropped?