commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dirk Verbeeck <dirk.verbe...@pandora.be>
Subject Re: [dbcp] Wait forever when get Ceonnction from data source
Date Tue, 18 Jan 2005 21:46:23 GMT
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


Mime
View raw message