commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Phil Steitz <phil.ste...@gmail.com>
Subject Re: [DBCP2] Timeout on PoolingDataSource#getConnection() ?
Date Fri, 01 May 2015 03:49:00 GMT
On 4/30/15 1:40 PM, Shawn Heisey wrote:
> I'm using dbcp2-2.1 and pool2-2.3.
>
> Is there any kind of timeout configurable (or even needed) when calling
> getConnection() on a PoolingDataSource?  I was looking over my code for
> possible problems and realized that I have no idea whether this call
> might block indefinitely or whether it will always finish (or throw an
> exception) within some reasonable timeframe.  The javadocs don't offer
> anything useful, which hopefully means that there is no possibility of a
> significant or indefinite pause.
>
> Below is the code I'm using to initialize.  In this code, dsMaster is an
> instance of javax.sql.DataSource, and one of the objects where I call
> getConnection().
>
>  ConnectionFactory cfMaster = new
> DriverManagerConnectionFactory(masterUrl, dbUser, dbPass);
>  PoolableConnectionFactory pcfMaster = new
> PoolableConnectionFactory(cfMaster, null);
>  pcfMaster.setValidationQuery(validationQuery);
>  pcfMaster.setValidationQueryTimeout(5);
>  opMaster = new GenericObjectPool<>(pcfMaster);
>  pcfMaster.setPool(opMaster);
>  dsMaster = new PoolingDataSource<>(opMaster);

Client blocking / timeout above is controlled by the properties set
on the GenericObjectPool.  By default, the blockWhenExhausted
property of a GOP is true and maxWaitMillis is -1, which means
clients will block indefinitely.   If you want clients to fail when
there are no connections available, set blockWhenExhausted to
false.  If you want to block for n millis, leave blockWhenExhausted
true and set maxWaitMillis to n.   Alternatively, you could just use
BasicDataSource, which is a little simpler to set up and exposes the
pool properties directly.

Phil
>
> Thanks,
> Shawn
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>



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


Mime
View raw message