aspose file tools*
The moose likes Tomcat and the fly likes database connection pooling - beginners questions on how-to Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "database connection pooling - beginners questions on how-to" Watch "database connection pooling - beginners questions on how-to" New topic
Author

database connection pooling - beginners questions on how-to

Roger F. Gay
Ranch Hand

Joined: Feb 16, 2007
Posts: 397
I'm currently running a single db connection as best I can. Even though I have a low traffic site, it seems a waste not to learn to use Tomcat's connection pool. I've heard it's great and not that hard to use. However, I've googled around a bit today and ... didn't find the article I'd read earlier on how it can be done in just three easy steps or whatever.

Anyway ... my first question is a very practical one. How do I tell if it's working? May seem like an odd question, but obviously a practical one. I have a connection now. How do I tell if I'm getting connections from the Tomcat pool? If it seems too weird a question, just let me know that I'll be making completely different calls than I am now (one article gave the impression that I won't ... which is why I ask) ... or whatever makes it obvious that I'm using the pool.

P.S. I'm hoping this will be the start of my questions (answers will come) and I'll be a connection pooling expert in no time.

Correlation does not prove causality.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

Fun fact: The connection pooling mechanisms used by Tomcat are plug-replaceable general-purpose components. The one that comes with Tomcat is the Apache dbcp product, which you can read up on by going to the appropriate sub-section of the apache.org website. I have used dbcp in stand-alone applications once or twice.

You can tell that the pool is working because the mechanism for obtaining a pool connection is completely different than it is for obtaining a one-off Connection object by brute force.

The brute force approach requires that your application code obtain a DriverManager for a specific Driver, URL, and credentials. The pooled approach defines these items in the pool definition external to the application and it publishes the pool's DataSource object as a JNDI lookup object. You obtain your Connection (which is actually a fa├žade object) from the DataSource and close it as soon as you are done with it. So the difference in code is considerable.


Customer surveys are for companies who didn't pay proper attention to begin with.
Roger F. Gay
Ranch Hand

Joined: Feb 16, 2007
Posts: 397
Thanks for helping me to get oriented. The following was particularly helpful.

Tim Holloway wrote:Fun fact: The connection pooling mechanisms used by Tomcat are plug-replaceable general-purpose components. The one that comes with Tomcat is the Apache dbcp product, which you can read up on by going to the appropriate sub-section of the apache.org website.


When I started with the Tomcat docs, someone had written "The JDBC Connection Pool org.apache.tomcat.jdbc.pool is a replacement or an alternative to the commons-dbcp connection pool." (source) .... OK, different dbcp I suppose? But for a new guy it was just enough to confuse ... for when I pursued the how to stuff, it was all about the dbcp ....

Source

So, now I'm guessing ok ... they use some commons-dbcp components, but it's still different. Anyway, you might be able to see why I came and asked for some orientation help. My first impression was that Tomcat's current pooling mechanism is completely different and I just couldn't find the right documentation for it.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

Actually, I am somewhat incorrect here. Depending on the version of Tomcat, the default pooler may or may not be the actual DBCP. Tomcat has included a pooler since its inception, and since it has been an integral installation component, the actual maintenance of it has tracked Tomcat more than it has any independent product.

I tend to forget that and simply say that DBCP is "the" pooler. For the most part, you can act like it is, although I believe that in Tomcat7 there are some distinctions worth noting.
Roger F. Gay
Ranch Hand

Joined: Feb 16, 2007
Posts: 397
I try to stay up to date, especially with new installations and my own development environment. I'm using version 7, along with Java 7 of course.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: database connection pooling - beginners questions on how-to