christopher@baus.net

Apache Tomcat 8.x database connection pooling issue

I spent a signficant amount of time hunting down a database problem while upgrading from Apache Tomcat 7.x to Tomcat 8.x. Hopefully this will save someone else some headaches.

First there are two pooling mechanisms which ship with Tomcat. The default is DBCP. There is also Tomcat connection pool, but I was unable to get it to work properly. It caused database deadlock problems with Microsoft SQL Server.

Second, while it is documented, a critical database connection pooling option changed names in DBCP between Tomcat 7.x and Tomcat 8.x versions, and I overlooked the change.

The setting “maxActive” is now called “maxTotal” in Tomcat 8.x if you are using the default DBCP connection pool. Annoyingly this setting is still called "maxActive" for the Tomcat connection pool.

This setting controls the total number of connections to the DB, so it makes huge performance difference. In our case, the application would deadlock while trying to get connections from the pool under load with default value, which is 8. Setting maxTotal to 256 solved our problem.

Show Comments