You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Paul Hsu <hs...@verizon.net> on 2005/01/17 17:38:43 UTC

Wait forever when get Ceonnction from data source

Hi,

I have one question about DBCP. I am connecting a database thruough Dharma odbc driver, so I use jdbc to odbc bridge,. It take a long time come back as expection when I try to call datasource.getConnection() and the server database daemon is not running. I cannot find any way to set up the time out in DBCP, I may miss some paramters. It would be appreciated if any one know how can I solve the problem.


Thanks,

Paul

Re: [dbcp] Wait forever when get Ceonnction from data source

Posted by Dirk Verbeeck <di...@pandora.be>.
Paul,

The problem is that you cannot safely interrupt the network 
communication that's going on inside the driver. If the driver doesn't 
expose the network layer timeout then you're stuck.

The only thing you can do is doing the driver.getConnection() in a 
separate thread and then your application thread can continue if no 
connection becomes available before the pool timeout.

If you are willing to experiment with this then I can give you some 
pointers. When you/we find a solution then it will be included into 
the official release. (that's the apache way)

So we need a seperate thread creating connections. Luckely this thread 
already exists. The evictor thread allocates new connections when 
needed. Set the "timeBetweenEvictionRunsMillis" property to start the 
thread. Using the "minIdle" property you can set the minimum number of 
connections that should be available in the pool.

The last thing is to disable the creation of new connections when an 
application thread borrows a connection from the pool (and the pool is 
empty). Unfortunally there isn't a configuration setting for this yet.
You will have to change commons-pool.

Create an extra property "boolean autoCreate;"
and change the following line in GenericObjectPool
http://jakarta.apache.org/commons/pool/xref/org/apache/commons/pool/impl/GenericObjectPool.html#789

if(_maxActive < 0 || _numActive < _maxActive) {
to
if (autoCreate && (_maxActive < 0 || _numActive < _maxActive)) {

In your case you set autoCreate to false and the application threads 
will wait until the background thread has created a connection (or 
another application thread returned one back into the pool).
The maxWait still applies.
http://jakarta.apache.org/commons/pool/xref/org/apache/commons/pool/impl/GenericObjectPool.html#799

The maxWait property is the connection timeout you needed.

Hope this helps, please report back the results of this experiment.

Cheers
Dirk

Paul Hsu wrote:

> Dirk,
> 
> Thank you for help. So you think there is no way we can ask DBCP to 
> abandon long waiting connection request  via jdbc/odbc driver? But if 
> the odbc driver does not provide the property to set up the connection 
> time out, it is better for DBCP to support. I think it will nice if 
> Jakata DBCP project can implement this. I write a time out java program 
> to abandon the connection request in certain period, but it is even 
> better if DBCP project team can add this to project.
> BTW, I thought that the maxWait is the max waiting time of a client can 
> borrow the connection from pool before return.
> 
> Paul



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [dbcp] Wait forever when get Ceonnction from data source

Posted by Paul Hsu <hs...@verizon.net>.
Dirk,

Thank you for help. So you think there is no way we can ask DBCP to abandon 
long waiting connection request  via jdbc/odbc driver? But if the odbc 
driver does not provide the property to set up the connection time out, it 
is better for DBCP to support. I think it will nice if Jakata DBCP project 
can implement this. I write a time out java program to abandon the 
connection request in certain period, but it is even better if DBCP project 
team can add this to project.
BTW, I thought that the maxWait is the max waiting time of a client can 
borrow the connection from pool before return.

Paul
----- Original Message ----- 
From: "Dirk Verbeeck" <di...@pandora.be>
To: "Jakarta Commons Developers List" <co...@jakarta.apache.org>
Sent: Monday, January 17, 2005 1:00 PM
Subject: Re: [dbcp] Wait forever when get Ceonnction from data source


> Connection timeout is a database driver specific property. You can set it 
> using the DBCP connectionProperties property. Or sometimes it is appended 
> to the URL.
>
> In your case you probably need to set the timeout on the odbc driver.
>
> Once the connection is in the pool then the maxWait can be used to limit 
> the pool waiting time.
>
> -- Dirk
>
> Paul Hsu wrote:
>> Hi,
>>
>> I have one question about DBCP. I am connecting a database thruough 
>> Dharma odbc driver, so I use jdbc to odbc bridge,. It take a long time 
>> come back as expection when I try to call datasource.getConnection() and 
>> the server database daemon is not running. I cannot find any way to set 
>> up the time out in DBCP, I may miss some paramters. It would be 
>> appreciated if any one know how can I solve the problem.
>>
>>
>> Thanks,
>>
>> Paul
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [dbcp] Wait forever when get Ceonnction from data source

Posted by Dirk Verbeeck <di...@pandora.be>.
Connection timeout is a database driver specific property. You can set 
it using the DBCP connectionProperties property. Or sometimes it is 
appended to the URL.

In your case you probably need to set the timeout on the odbc driver.

Once the connection is in the pool then the maxWait can be used to 
limit the pool waiting time.

-- Dirk

Paul Hsu wrote:
> Hi,
> 
> I have one question about DBCP. I am connecting a database thruough Dharma odbc driver, so I use jdbc to odbc bridge,. It take a long time come back as expection when I try to call datasource.getConnection() and the server database daemon is not running. I cannot find any way to set up the time out in DBCP, I may miss some paramters. It would be appreciated if any one know how can I solve the problem.
> 
> 
> Thanks,
> 
> Paul



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org