commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dirk Verbeeck <dirk.verbe...@pandora.be>
Subject Re: DBCP PoolingDataSource example
Date Wed, 19 Nov 2003 20:14:03 GMT
You can setMinIdle() to always have a minium amount of idle connection in the 
pool. (not only at the start of the pool but the whole time)
The minIdle check is done in the evictor thread so timeBetweenEvictionRunsMillis 
  has to be set to a non negative-value. (you can optionally turn off the 
eviction by setting  numTestsPerEvictionRun to zero or just set 
minEvictableIdleTimeMillis very high).

A more simple way to create a number of connections at startup is to use the 
pool.addObject() method.
(add the following after creating the PoolableConnectionFactory)

for (int i=0 ; i<initialsize ; i++) {
    connectionPool.addObject()
}

-- Dirk


Natarajan Arun wrote:
> Hi All,
> When using DBCP what parameter needs to be set on the ObjectPool so that a
> minimum number of connections are created when the pool instance is created
> ?? I thought the setMinIdle() does this, but doesn't look so.
> 
> The code I use:
> 
> 		try {
> 			Class.forName(driver).newInstance();
> 			System.out.println("No Errors occured 1");
> 		} catch (Exception e) {
> 			System.out.println("class for name failed" + e);
> 		}
> 		connectionPool = new GenericObjectPool(null);
> 		connectionPool.setMaxActive(maxConn);
> 		connectionPool.setMinIdle(minConn);
> 
> //connectionPool.setWhenExhaustedAction(connectionPool.WHEN_EXHAUSTED_GROW);
>  -- NEED TO TEST THIS!!!
> 		ConnectionFactory connectionFactory = new
> DriverManagerConnectionFactory(URL,null);
> 		PoolableConnectionFactory poolableConnectionFactory = new
> PoolableConnectionFactory(connectionFactory,connectionPool,null,null,false,t
> rue);
> 		ds = new PoolingDataSource(connectionPool);
> 		System.out.println("Data source inited successfuly");
> 
> Thanks,
> Arun N
> 
> 
> ---------------------------------------------------------------------
> 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


Mime
View raw message