atom feed11 messages in org.apache.commons.devRE: Question about DBCP
FromSent OnAttachments
Steve CohenApr 29, 2002 9:29 pm.txt
Brekke, JeffApr 30, 2002 7:03 am 
Eric PughApr 30, 2002 7:19 am 
Eric PughApr 30, 2002 7:25 am.java
AnjanApr 30, 2002 9:41 am 
Eric PughApr 30, 2002 10:18 am 
Eric PughApr 30, 2002 10:30 am 
Craig R. McClanahanApr 30, 2002 11:06 am 
Anjan BacchuApr 30, 2002 11:40 am 
Eric PughApr 30, 2002 1:53 pm 
Craig R. McClanahanApr 30, 2002 2:19 pm 
Subject:RE: Question about DBCP
From:Craig R. McClanahan (crai@apache.org)
Date:Apr 30, 2002 2:19:13 pm
List:org.apache.commons.dev

On Tue, 30 Apr 2002, Eric Pugh wrote:

Date: Tue, 30 Apr 2002 16:54:21 -0400 From: Eric Pugh <epu@upstate.com> Reply-To: Jakarta Commons Developers List <comm@jakarta.apache.org> To: 'Jakarta Commons Developers List' <comm@jakarta.apache.org> 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

Craig