On 6/13/07, Seva Popov <[EMAIL PROTECTED]> wrote:

Hi,

I am using Tomcat 5.5.9 and have configured
OracleConnectionPoolDataSource as the physical connection to the
database and DBCP's PerUserPoolDataSource as the pool of logical
connections to the same database (i.e. using the mentioned
OracleConnectionPoolDataSource).

Here is the configuration of my PerUserPoolDataSource (note the pool
size):

<Resource name="jdbc/MyPool"
        auth="Container"

type="org.apache.tomcat.dbcp.dbcp.datasources.PerUserPoolDataSource"
factory="org.apache.tomcat.dbcp.dbcp.datasources.PerUserPoolDataSourceFa
ctory"
        dataSourceName="java:comp/env/jdbc/MyCPDS"
        maxActive="2"
        maxIdle="2"
        maxWait="5"/>


For PerUserPoolDataSource, the parameters are specified differently,
since you can set defaults for the pool and also override them per
user.  See
http://jakarta.apache.org/commons/dbcp/api-1.2.2/org/apache/commons/dbcp/datasources/PerUserPoolDataSource.html
for the property names and
http://wiki.apache.org/jakarta-commons/DBCP for an example config.

Now, I am using the below test JSP page to see that the connections are
reused from the pool:

<jsp:directive.page import="javax.naming.Context" />
<jsp:directive.page import="javax.naming.InitialContext" />
<jsp:directive.page import="javax.sql.DataSource" />
<jsp:directive.page import="java.sql.Connection" />
  <html>
    Hello
<%
Context initContext = new InitialContext();
Context envContext  = (Context) initContext.lookup("java:/comp/env");

DataSource ds = (DataSource) envContext.lookup("jdbc/MyPool");
System.out.println("DataSource: " + ds);

Connection conn1 = ds.getConnection("user", "psw ");
System.out.println("Connection 1: " + conn1);

Connection conn2 = ds.getConnection("user", "psw ");
System.out.println("Connection 2: " + conn2);

conn2.close(); // closing this connection to return it to the pool

Connection conn3 = ds.getConnection("user", "psw ");
System.out.println("Connection 3: " + conn3);

Conn1.close();
conn3.close();
%>
</html>

Here is the output (and as you see all connections are different
objects):
DataSource:
[EMAIL PROTECTED]
Connection 1: [EMAIL PROTECTED]
Connection 2: [EMAIL PROTECTED]
Connection 3: [EMAIL PROTECTED]

My questions:
1. Firstly, I've expected to get the same connection object (as for the
connection #2) when I've obtained the 3thd connection because the pool
max size is "2", the connection #1 is still active at the moment, and
the connection #2 is closed and supposed to be returned to the pool.

For PerUserPoolDataSource this is most likely due to maxActive,
maxIdle parameters not being recognized.

2. Secondly, I've expected to get the DBCP's logical
org.apache.tomcat.dbcp.dbcp.PoolableConnection but I've got the physical
Oracle connection instead.

Where and how do you specify the Oracle driver?  What you should get
back is a a PooledConnection.

I've got the same results with the DBCP's SharedPoolDataSource.

The maxActive, maxIdle parameters should work for
SharedPoolDataSource.  Can you share the config that you used for this
test?

Phil

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to