tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Romen Law" <>
Subject tomcat 4.0.* DB connection pool gocha's
Date Fri, 10 May 2002 03:29:08 GMT

As many people mentioned, there is a lot of confusion about databse connection pooling in
tomcat 4. I spent some time trying all sorts of combinations (tyrex, dbcp, etc.) to get connection
pooling working because there is little documentation on this topic and the products it uses.
I got it working using tomcat's default library (tyrex) and here is what I found:
1. in web.xml, do this:

2. in server.xml do this (I am using Sybase with jconn2.jar, which comes with SybConnectionPoolDataSource):

          <Resource name="jdbc/MyDB" auth="Container"
          <ResourceParams name="jdbc/MyDB">

3. in my java code, do this:
            Context ctx=new InitialContext();
            Context envCtx=(Context)ctx.lookup("java:comp/env");
            ConnectionPoolDataSource pds=(ConnectionPoolDataSource)envCtx.lookup("jdbc/MyDB");
            connection = pds.getPooledConnection().getConnection();

4. the above works with jdk1.4 using tomcat 4.0.3 (note that the tomcat lite binary distribution
is missing tyrex*.jar, so if you used that, you need to manually put the jar in tomcat's common/lib)

5. to get the above to work under jdk131_* using tomcat 4.0.3, I had to put jta.jar in tomcat's
common/lib, because it was complaining about javax.transaction... class missing.

6. note that there is no way to specify the connection pool size, etc. In tomcat 4.1's documentation
(JNDI-HOW-TO) it mentions parameters like maxIdle, maxActive, etc. Therefore, I believe these
are not supported in tomcat 4.0.* but is in tomcat 4.1's product development plan.

7. and this setting really pools the connection. I checked this using netstat and saw that
there was one or two connections established, as opposed to dozens of them (when I used SybDataSource
in server.xml and DataSource in java code) when I madly clicked the links on my web page (each
link does a db query). The only thing is, the connection's life time seems very short (a few
seconds idle) and I could not control the pool size, etc. as mentioned in above point.

Hope I have helped.


View raw message