Two Laptop Bag*
The moose likes Tomcat and the fly likes DBCP connection pooling with multiple web-apps Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "DBCP connection pooling with multiple web-apps" Watch "DBCP connection pooling with multiple web-apps" New topic
Author

DBCP connection pooling with multiple web-apps

Kevin Kilbane
Ranch Hand

Joined: Sep 22, 2008
Posts: 42
Hi. I have set up connection pooling within Tomcat using DBCP. It is working fine but I am concerned that that I may have set up a connection pool for each web-app as opposed to one connection pool shared amongst all web-apps.

I want it so that all web-apps running in the one instance of Tomcat retrieve and return connections from/to the same connection pool.

I DON'T want it so that each web-app is working off it's own connection pool and there are multiple connection pools in existence on the same instance of Tomcat.

Can someone tell me if this is the case based on my setup outlined below? Thanks.

I have this in my TOMCAT_HOME/conf/server.xml:

<Server>
<GlobalNamingResource>
<Environment>…</Environment>
<Resource>….</Resource>
<Resource
name = "jdbc/DBName"
auth = "Container"
type = "javax.sql.DataSource"
driverClassName = "driverName"
url = "jdbc:DBurl"
username = "user"
password = "pass"
maxActive = "20"
maxIdle = "5"
maxWait = "100"
removeAbandoned = "true"
removeAbandonedTimeout = "15"
accessToUnderlyingConnectionAllowed="true"/>
</GlobalNamingResource>
</Server>

I have this in my TOMCAT_HOME/conf/web.xml:

<resource-ref>
<res-ref-name>jdbc/DBName</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
Kevin Kilbane
Ranch Hand

Joined: Sep 22, 2008
Posts: 42
I'm using Tomcat 5.5.27 by the way, if that makes a difference.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15951
    
  19

You can define a connection pool in the deployment Context on a per-application basis, but I'm not sure why you think you gain a benefit over using a pool that's shared between webapps.

Connections pulled from a connection pool are supposedly 100% generic, so which connection and what pool shouldn't be making a difference in your applications. In fact, a shared pool is usually going to be better, since it allows you to keep fewer overall connections actually opened to the DBMS server.

The main reasons for app-specific pooling would be if you need to connect to a different database, if the app is so critical that it cannot tolerate being crowded out of the pool by other apps, or if you have something that you want to be able to just drop in as a unit without hooking it into an existing pool.


Customer surveys are for companies who didn't pay proper attention to begin with.
Kevin Kilbane
Ranch Hand

Joined: Sep 22, 2008
Posts: 42
Tim Holloway wrote:You can define a connection pool in the deployment Context on a per-application basis, but I'm not sure why you think you gain a benefit over using a pool that's shared between webapps.

Connections pulled from a connection pool are supposedly 100% generic, so which connection and what pool shouldn't be making a difference in your applications. In fact, a shared pool is usually going to be better, since it allows you to keep fewer overall connections actually opened to the DBMS server.

The main reasons for app-specific pooling would be if you need to connect to a different database, if the app is so critical that it cannot tolerate being crowded out of the pool by other apps, or if you have something that you want to be able to just drop in as a unit without hooking it into an existing pool.


Hi Tim, thanks for the response. I think you misunderstood my query though - I want the pool to be shared between web-apps. My question is have I set Tomcat up to have a shared pool or have I set it up to have a pool per app (based on the config details I included in my first post)? Thanks.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15951
    
  19

OK, so I read it exactly backwards. Oops.

I think you can define the pool in server.xml in that case, though I recommend you check the tomcat docs.
 
wood burning stoves
 
subject: DBCP connection pooling with multiple web-apps
 
Similar Threads
TOMCAT 5.5.4 + Datasource in ROOT not working
Juddi DB connection problem
tomcat/mysql configuration help?
db connection pooling to mssql from Tomcat 4.0.6
JNDI problem