Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DBCP connection pooling with multiple web-apps

 
Kevin Kilbane
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using Tomcat 5.5.27 by the way, if that makes a difference.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18276
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kevin Kilbane
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18276
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic