commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Seva Popov" <>
Subject RE: [DBCP] The PerUserPoolDataSource/SharedPoolDataSource does not reuse/pool the db connections
Date Wed, 20 Jun 2007 07:34:11 GMT


From: Phil Steitz []
Sent: Tue 6/19/2007 9:49 PM
To: Jakarta Commons Users List
Subject: Re: [DBCP] The PerUserPoolDataSource/SharedPoolDataSource does not reuse/pool the
db connections

Two more comments on this.  First, by modifying the jsp to cast the ds
as a SharedPoolDataSource, you can call the getNumActive and
getNumIdle methods to verify that the pool is working correctly:

[Seva] Yes, this test verifies that the pool observes the max active and max idle config parameters.
And it seems that after the connection was active it becomes idle, i.e. it is still in the
pool.  But this test can not verify for sure that the pool is reusing the physical database
connections. For example, one can easily break the above by closing the underlying physical
connection directly in the client code. 

SharedPoolDataSource ds = (SharedPoolDataSource)
System.out.println("DataSource: " + ds);
System.out.println("Num Active init " + ds.getNumActive());
System.out.println("Num Idle init " + ds.getNumIdle());

Connection conn1 = ds.getConnection("phil", "zft0done");
System.out.println("Connection 1: " + conn1);
System.out.println("Num Active one open " + ds.getNumActive());
System.out.println("Num Idle one open " + ds.getNumIdle());

For PerUserPoolDataSource, you need to supply uid/pwd to the getNumXxx
methods per the javadoc to get correct counts.

For SharedPoolDataSource, I get the expected output with the setup I
described above:
DataSource: org.apache.tomcat.dbcp.dbcp.datasources.SharedPoolDataSource@1ad98ef
Num Active init 0
Num Idle init 0
Connection 1: oracle.jdbc.driver.LogicalConnection@16d2702
Num Active one open 1
Num Idle one open 0
Connection 2: oracle.jdbc.driver.LogicalConnection@1556d12
Num Active two open 2
Num Idle two open 0
Num Active 2 closed 1
Num Idle 2 closed 1
Connection 3: oracle.jdbc.driver.LogicalConnection@16be68f
Num Active 3rd open 2
Num Idle 3rd open 0
Num Active 1 closed 1
Num Idle 1 closed 1
Num Active all closed 0
Num Idle all closed 2

Second, if for some reason your version of the Oracle drivers is not
working correctly, you can use a cpds adapter.  See the Wiki example
referenced above or the package javadoc for o.a.c.dbcp.cpsdadapter for
info on how to configure this.

[Seva] Yes, I've realized the same today and was going to switch to CPDS adapter tomorrow
but after I got your previous email things were clarified and I verified the Oracle driver
is working correctly.


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

View raw message