[dbcp] use of BasicDataSourceFactory.createDataSource(Properties)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[dbcp] use of BasicDataSourceFactory.createDataSource(Properties)

Pramodh Peddi
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:

 

* Every time BasicDataSource is created, we need to create a
Properties object. Is this not going to be a performance hit?
* 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.
* If BasicDataSource caching is ok, do read-only methods like
getNumIdle() and getNumActive() return the right values?
* Do I still need to define the Resource (<Resource
name="jdbc/ImprivataDB" auth="Container" type="javax.sql.DataSource"/>)
in server.xml and web.xml?
* Are there any examples around which uses
BasicDataSourceFactory.createDataSource(Properties) to create
BasicDataSource?

 

Thanks in advance for the answers,

 

Pramodh.

 

Reply | Threaded
Open this post in threaded view
|

Re: [dbcp] use of BasicDataSourceFactory.createDataSource(Properties)

Dirk Verbeeck
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: [hidden email]
For additional commands, e-mail: [hidden email]