commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject RE: Question about DBCP
Date Tue, 30 Apr 2002 21:19:35 GMT

On Tue, 30 Apr 2002, Eric Pugh wrote:

> Date: Tue, 30 Apr 2002 16:54:21 -0400
> From: Eric Pugh <>
> Reply-To: Jakarta Commons Developers List <>
> To: 'Jakarta Commons Developers List' <>
> Subject: RE: Question about DBCP
> Well,
> I wanted to post to the list what I learned!  Firstly, thanks to Craig for
> his quick patch on exposing the number of active and idle connections for
> BasicDataSource.
> I am able to successfully pool connections for use by DbForms.  That is
> wonderful!  I am currently running on MSSQLServer 2000 and use the MS
> JDBCODBC driver.  I ended up using the BasicDataSource because it was easy.
> Some things I have noticed/have questions:
> 1) If I don't provide a maxActive, then when I go for the first connection,
> nothing happends.

Need to look at that one.  According to the docs, setting maxActive to
zero (or not setting it at all, because this is the default) is supposed
to mean no limit.

> 2) What exactly does the idle mean?  At one point I had 5 connections
> running according to the database server, but according to the the numIdle,
> numActive, I only had 2 active, 0 idle..  Are there some extra connections
> as overhead?  I know I wasn't using any of them for other processes.

DBCP also knows how to destroy idle connections if there are more than
maxWait of them.  Could this be happening to you?

> 3) What is the difference between the BasicDataSource and the
> BasicDataSourceFactory?  Is BasicDataSource what I should be using to pool
> my db connections for a web app?

BasicDataSource is an implementation of javax.sql.DataSource (although not
the only one that could be built on top of the pool and dbcp packages).
It is what you'd use in a stand-alone application where you didn't want to
compose a connection pool yourself.

BasicDataSourceFactory is a JNDI ObjectFactory implementation that can be
registered in a JNDI environment, and use it to create a BasicDataSource
implementation the first time it is retrieved.  This is how Tomcat
actually creates the data source instance.

> 4) The code for the Tomcat 4.0 DBCPPoolFactory (sp?) in  CVS seems to have
> been replaced with the text of an Ant Build file.  (I got that browsing via
> the web cvs).

Still looks ok to me in the head branch (although this is the code I
migrated into DBCP to create the BasicDataSourceFactory class.

> How I configured my DataSource:
> try{
>	if (dataSource == null){
>		dataSource = new BasicDataSource();
>		dataSource.setDriverClassName(conClass);
>		dataSource.setUrl(name);
>		dataSource.setPassword(password);
>		dataSource.setUsername(username);
>		dataSource.setValidationQuery(null);
>		dataSource.setMaxActive(20);
>		dataSource.setMaxIdle(5);
>		dataSource.setMaxWait(-1);
>	}
>	logCat.debug("Current Connections: active:" + dataSource.getNumActive()
>          + ", idle:" + dataSource.getNumIdle());
> 	return dataSource.getConnection();
> }
> catch (Exception e){
> 	logCat.error(e);
> 	e.printStackTrace();
> 	return null;
> }
> Thank you very much for the help,
> Eric


To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message