Explaining jdbc-pool, a High Concurrency Alternative to Connection Pooling Module

posted by fhanik on March 12, 2010 02:23 PM

Why another connection pool project

In this article we are going to explore one of the modules that is being developed in the Tomcat development trunk. The module named, jdbc-pool, is exactly that, an implementation of pooling of JDBC resources.

Connection pools have been around for a long time. I wrote one myself in 1997 when I first was introduced to Java, and used that for a long time in different projects I worked on. When JDBC came up, developers quickly realized that pooling JDBC connections would be beneficial for performance, and also a way to siphon connections and control the resource usage on the database server. This was especially important in horizontally scaled clusters where the database was always a risk of being overloaded. In those days we typically ran 1, 2 and sometimes 4 CPU machines for the application servers.

Connection pooling quickly became something that J2EE vendors developed in-house to integrate with their transaction services and became proprietary and integrated into the server itself. Outside of the J2EE containers a number of open source projects popped up. A few examples are Proxool, Apache Commons DBCP, C3P0 and Poolman. These are the most common ones we encounter in the field. Apache Tomcat has for very many years relied on DBCP to provide Tomcat users with a connection pooling implementation.

All of these open source projects have their pros and cons, but they all have something in common. They have become fairly stagnant and the code bases have not continued to evolve to meet new features in the Java language and are not optimized for multicore hardware that is increasingly becoming the common platform to deploy Java applications on. Some of the projects have also suffered from unneeded complexity in the source code, most likely one of the main reasons the project code is not moving forward, making it hard to maintain and easy to break.

Out of the four open source projects mentioned above, the two we see in Apache Tomcat deployments today are Commons DBCP and C3P0. A short summary of these two projects would be:

Commons DBCP

  • Ships with Apache Tomcat, used because it is readily available
  • Fairly stable code base
  • Plagued by dead locks for a very long time
  • Customer on lower clock speed but higher parallelism often complain about throughput bottlenecks


  • Often used instead of DBCP
  • Based on our experience in the field, still fairly buggy
  • Reputation to perform better than DBCP, albeit our results show different

Both of these implementations are fairly complex. DBCP is built on top of the Apache Commons Pool project, and all together forms a code base of over 60 source files. C3P0 has grown to over 200 source files. Yet both pools fall short on features, to mention a few:

  • Pools are often statically tied to a Java version, meaning if the pool was written for Java 5, it wont have the java.sql and javax.sql interfaces compatible with Java 6. A user would typically receive a NoSuchMethodException when trying to execute one of the newer interface methods.
  • The pools are limited to java.sql.Driver interface, making it impossible to pool resources from a javax.sql.DataSource
  • No support for XA data sources
  • No flexibility for plugging in new features

So back to our question, why yet another pool project? The answer was simple, we needed better performance and more features. We also believed that taking on one of the legacy implementations would require rewriting a majority of the code base. So, it came to make a judgement call, do we want to rewrite 60+ sources files, or even 200+.

I know what you're probably thinking, here is yet another engineer that believes in rewriting from scratch rather than contributing to the existing code base. In almost every case, I prefer to reuse and fix than rewrite. However, after carefully judging the following questions:

  • How many lines of code do we actually need to provide the exact same implementation of Commons DBCP?
  • Can we make my implementation flexible enough to expose all the methods of java.sql.Connection that the driver exposes?
  • Can we provide a framework for exposing additional features?
  • Can we make the implementation scale in multi core environments/?

The next challenge we faced with such a project, within the Apache Software Foundation, was how to build a community around the project. Community is often grown by having lots of code that is not quite finished, meaning, there is work to be done in multiple areas making it enjoyable for a group to work together.

By this time, we had a prototype, it was 8 source files, and provided all the features of the other pools combined. Not all that exciting for a group of Java developers. Trying to fire off a separate project would probably not be very fruitful from a community perspective. We've since then grown it to 24 source files mostly by creating prebuilt addons that can be configured.

And so the jdbc-pool module was started.

The jdbc-pool did get some early adoption and the number of bugs was very low. Most early bugs were actual workarounds for typical use of the java.sql interfaces, calling close multiple times on a connection etc.

Today we see jdbc-pool, even in its unreleased state, several cases of production use. SpringSource ships the pool module with its tc Server product and you can already read about it in blog posts.

The jdbc-pool has an almost identical configuration as the Commons DBCP pool, in order to provide an easy migration path. For users already using Apache Tomcat and DBCP, the only difference would be the factory attribute  factory="org.apache.tomcat.jdbc.pool.DataSourceFactory".

For users of dependency injection frameworks, like the Spring Framework it's easy to just configure the org.apache.tomcat.jdbc.pool.DataSource bean.

Folks, that is why we have yet another pool module for JDBC connections. Over the next few articles, I will be digging deeper into:

  • Performance of jdbc-pool
  • The feature set, how and when to use it
  • The actual implementation and why it scales
  • How to build extensions

Filip Hanik is a Senior Software Engineer for the SpringSource Division of VMware, Inc. (NYSE: VMW) and a key participant in the company's Apache Tomcat initiatives. Filip brings 15 years of extensive experience in architecture, design and development of distributed application frameworks and containers and is recognized for his top-quality system development skills and continuous participation of Open Source development projects. Filip is an Apache Software Foundation member and a committer to the Apache Tomcat project where he is a leading authority on Tomcat clustering and a key contributor to the core of the platform. Filip has made contributions to software initiatives for, Sony Music, France Telecom and has held a variety of senior software engineering positions with technology companies in both the United States and Sweden. He received his education at Chalmers University of Technology in Gothenburg, Sweden where he majored in Computer Science and Computer Engineering.


Switching from C3P0...

Hi Filip.

I'm using C3P0 in a product I work on. I occasionally have problems with deadlocks, but in general it works pretty well. Do you think jdbc-pool is mature enough to start considering an eventual switch?


RE: Switching from C3P0...

Hi Matt, absolutely. The jdbc-pool has faired very well in many environments that we've seen. So go for the switch.
What we see as common pitfalls, is that some code doesn't have proper closure of statements, for that they would use the StatementFinalizer, or applications don't reset auto commit and read only values, and for that they would use the ConnectionState interceptor.
We have an upcoming article about configuration, that will talk more in depth about these issues.

If you run into any problems, you can ping me on my email, my id is fhanik, or ask a question on the tomcat user mailing list.


RE: Switching from C3P0...

Thanks Filip. I'm working on a product that's about to have a release. Once that's out, I'll give jdbc-pool a try. Maybe I'll be able to include it in the next release. :)


Sorry for the slow reply - for some reason my dev build of Chrome is consistently unhappy with the reply page. It took me a few days to get around to writing it in Firefox. ;)

On this page, you'll see my

On this page, you'll see my profile, please read this information. Save The Marriage System

On this page, you'll see my

On this page, you'll see my profile, please read this information. Ways To Get Your Ex Back

Welcome to the party of my

Welcome to the party of my life here you will learn everything about me. Survive In Bed

This is helpful, nonetheless

This is helpful, nonetheless it can be crucial so that you can check out the following website: audiometry

This is very appealing,

This is very appealing, however , it is very important that will mouse click on the connection: How To Give A Hand Job

During this website, you will

During this website, you will see this shape, i highly recommend you learn this review. f4x bodybuilding rebelmouse

You possess lifted an

You possess lifted an essential offspring..Blesss for using..I would want to study better latest transactions from this blog..preserve posting.. How to Turn a Guy On

There you can download for

There you can download for free, see the first of these data. sexosur

Very interesting information,

Very interesting information, worth recommending. However, I recommend this: sexosur

Mmm.. estimable to be here in

Mmm.. estimable to be here in your report or notify, whatever, I repute I should moreover process strong for my have website want I play some salubrious further updated busy in your location. sexonorte

This is important, though

This is important, though it's necessary to help you head over to it weblink:

On this page you can read

On this page you can read my interests, write something special. The Bonding Code Review

great post

hello all, introduce me from Indonesia.
I manage the best quality wholesale furniture business, for those of you who are in need of furniture can directly contact me.

mebel murah mebel jati furniture online kursi tamu

Good dear!

Blessings come in many disguises. There's always something to learn from everything we go through.

Beautifully written article.

Beautifully written article. This is exactly why I've bookmarked your blog. I always want to read your articles, new or old. I hope you will keep this going on.
Ink Cartridges


I believe your site is precisely exactly what I've been searching for; this solutions a lot of associated with my personal queries. michael spencer gilroy


Thanks for publishing this

Thanks for publishing this amazing post today. You've been doing a really good job for the past few months and check interesting article. I just hope that you will keep doing the same job!!

I had been having some

I had been having some problems on this topic, but after reading this tremendously written blog post, all my queries have vanished. Good job! learn how to save energy

i read a lot of stuff and i

i read a lot of stuff and i found that the way of writing to clearifing that exactly want to say was very good so i am impressed and ilike to come again in future..
Seaside Residences Frasers

I found that site very

I found that site very usefull and this survey is very cirious, I ' ve never seen a blog that demand a survey for this actions, very curious...
how much does an electrician make

Nice to read your article! I

Nice to read your article! I am looking forward to sharing your adventures and experiences.
go at this site

The information I have gotten

The information I have gotten from this articles is absolutely essential for me. I am very thankful to the writer who has shared all of this information with us. Keep giving more articles like this. When Is Christmas

Good post but I was wondering

Good post but I was wondering if you could write a litter more on this subject? I’d be very thankful if you could elaborate a little bit further. Appreciate it!
des moines tattoo

Yngwie Malmsteen Guitar

Yngwie Malmsteen Guitar Setup. As far as electric guitars, there is just a single model that Malmsteen is truly enthusiastic about. On the off chance that you weren't acquainted with Malmsteen's work, and you chose to play one of his collections on your stereo, the last guitar you would envision him utilizing is the Fender Stratocaster. Be that as it may, Strats are his frail spot. That, as well as there is a certain scope of Stratocasters that he plays. Guitars made in the period from 1968 to 1972 are worthy, while whatever else is most certainly not. His blonde Strat has turned into his mark thing which is most likely as famous as Malmsteen himself
Dimebag Darrell Guitar Setup

Thank you so much for the

Thank you so much for the post you do. I like your post and all you share with us is up to date and quite informative, i would like to bookmark the page so i can come here again to read you, as you have done a wonderful job.
homes for sale

Nice post! This is a very

Nice post! This is a very nice blog that I will definitively come back to more times this year! Thanks for informative post.
check this

Hello There. I found your

Hello There. I found your blog using msn. This is an extremely well written article. I will be sure to bookmark it and return to read more of your useful information. Thanks for the post. I’ll certainly comeback.
come far allungare il pene

Its a great pleasure reading

Its a great pleasure reading your post.Its full of information I am looking for and I love to post a comment that "The content of your post is awesome" Great work.
gummy for hunger suppression

I would like to thank you for

I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. Thanks...
casa Miami

I recently found many useful

I recently found many useful information in your website especially this blog page. Among the lots of comments on your articles. Thanks for sharing.
cheap dedicated server backup server

thanks this is good

thanks this is good blog.
cheap dedicated servers linux

You’ve got some interesting

You’ve got some interesting points in this article. I would have never considered any of these if I didn’t come across this. Thanks!.
O'level geography tuition

Your article has piqued a lot

Your article has piqued a lot of positive interest. I can see why since you have done such a good job of making it interesting.
cupom de desconto levis

Wow, cool post. I’d like to

Wow, cool post. I’d like to write like this too – taking time and real hard work to make a great article… but I put things off too much and never seem to get started. Thanks though.
Fast Shop

i am for the first time here.

i am for the first time here. I found this board and I in finding It truly helpful & it helped me out a lot. I hope to present something back and help others such as you helped me.
debt collectors auckland

I really loved reading your

I really loved reading your blog. It was very well authored and easy to understand. Unlike other blogs I have read which are really not that good.Thanks alot!
Mona Media

The post is written in very a

The post is written in very a good manner and it contains many useful information for me.
designer clothes sale

Great Article it its really

Great Article it its really informative and innovative keep us posted with new updates. its was really valuable. thanks a lot. children's charity

I love this blog!! The flash

I love this blog!! The flash up the top is awesome!!
children in need

I would like to say that this

I would like to say that this blog really convinced me to do it! Thanks, very good post.
culver city real estate agent

This was really an

This was really an interesting topic and I kinda agree with what you have mentioned here!

I read that Post and got it

I read that Post and got it fine and informative. Please share more like that...

These are some great tools

These are some great tools that i definitely use for SEO work. This is a great list to use in the future..
buy products


I don’t even know how I ended up here, but I thought this post was good. I do not know who you are but certainly you are going to a famous blogger if you aren’t already Cheers! holiday destinations in Mauritius


Superbly written article, if

Superbly written article, if only all bloggers offered the same content as you, the internet would be a far better place..
Yio Chu Kang EC

I am hoping the same best

I am hoping the same best effort from you in the future as well. In fact your creative writing skills has inspired me.

Nice Informative Blog having

Nice Informative Blog having nice sharing..
guest post

Post new comment

This question is for testing whether you are a human visitor and to prevent automated spam submissions.