You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Natarajan Arun <na...@bah.com> on 2003/11/17 03:08:10 UTC

DBCP PoolingDataSource example

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


RE: DBCP PoolingDataSource example

Posted by Arun Natarajan <an...@gmu.edu>.
Great! thanks, i used the second appraoch.

Regards,
Arun N

-----Original Message-----
From: Dirk Verbeeck [mailto:dirk.verbeeck@pandora.be]
Sent: Wednesday, November 19, 2003 3:14 PM
To: Jakarta Commons Users List
Subject: Re: DBCP PoolingDataSource example


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



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


RE: DBCP PoolingDataSource example

Posted by Arun Natarajan <an...@gmu.edu>.
Thanks, that did the trick. I used the second approach.

Regards,
Arun N

-----Original Message-----
From: Dirk Verbeeck [mailto:dirk.verbeeck@pandora.be]
Sent: Wednesday, November 19, 2003 3:14 PM
To: Jakarta Commons Users List
Subject: Re: DBCP PoolingDataSource example


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



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


Re: DBCP PoolingDataSource example

Posted by Dirk Verbeeck <di...@pandora.be>.
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


Re: DBCP PoolingDataSource example

Posted by Stephen Turner <st...@MIT.EDU>.
I believe maxIdle is the parameter you need. There's a good explanation
of the parameters at

http://www.mail-archive.com/commons-user@jakarta.apache.org/msg04945.html

Steve Turner

At 09:08 PM 11/16/2003 -0500, you 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.