• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

database connection pooling - beginners questions on how-to

 
Ranch Hand
Posts: 409
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Saloon Keeper
Posts: 24294
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Roger F. Gay
Ranch Hand
Posts: 409
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 24294
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 409
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic