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.
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
Joined: Feb 16, 2007
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 ....
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.
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
Joined: Feb 16, 2007
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.