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] use of BasicDataSourceFactory.createDataSource(Properties)
Date Thu, 23 Jun 2005 06:16:35 GMT
Hi,
Answers inline

Pramodh Peddi wrote:
> Hi DBCP experts,
> Is anyone using BasicDataSourceFactory.createDataSource(Properties) to
> create a BasicDataSource object (using version 1.2)? I have not yet used
> this, but I desire to use this. I can see few 'issues' when I use it:

This method is used by tomcat so a lot of users are using this piece of 
code.

> *	Every time BasicDataSource is created, we need to create a
> Properties object. Is this not going to be a performance hit?

Creating the Properties object isn't the performance hit. Always 
recreating a BasicDataSource is. The BasicDataSource is your pool of 
connections, if you are always recreating it then you don't have pooling 
behaviour.

> *	To avoid the above performance hit, is it ok if I cache
> BasicDataSource (make it static variable) and re-use it every time
> connection is borrowed from pool.

Yes, this is the normal use of a BasicDataSource. You create the pool 
once and then borrow connections from it. BasicDataSource is thread-safe 
so you don't need to add synchronizations.

> *	If BasicDataSource caching is ok, do read-only methods like
> getNumIdle() and getNumActive() return the right values?

Yes

> *	Do I still need to define the Resource (<Resource
> name="jdbc/ImprivataDB" auth="Container" type="javax.sql.DataSource"/>)
> in server.xml and web.xml?

No, if you are creating a BasicDataSource yourself then you don't need 
to configure anything else.
The configuration files server.xml and web.xml are only used when tomcat 
  creates the BasicDataSource and you get the DataSource using JNDI.

> *	Are there any examples around which uses
> BasicDataSourceFactory.createDataSource(Properties) to create
> BasicDataSource?

http://jakarta.apache.org/commons/dbcp/xref-test/org/apache/commons/dbcp/TestBasicDataSourceFactory.html#50

> Thanks in advance for the answers, 
> Pramodh.

Cheers
Dirk


---------------------------------------------------------------------
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