4 Mistakes To Avoid On Apache Tomcat

posted by mthomas on August 3, 2011 06:50 AM

As a VMware engineer dedicated to building Apache Tomcat and vFabric tc Server , I get the opportunity to see a lot of issues across the official Apache Tomcat public mailing lists, as well as VMware’s private professional support queue for both Apache Tomcat and tc Server. Typical of any software issue tracker, many of the issues logged could be avoided with a little better understanding of the Tomcat applications. Here are a few tips that may be useful to keep in mind:

Understanding Global vs Application Context.xml Files

There are two different types of context.xml files: one is global, and the other is specific to each web application. The problem with editing the global context.xml file is, as its name implies, that it affects every web application running on that Tomcat instance. So for instance, if you have 10 web applications, and create a new JNDI datasource with 50 connections to the database in the global context.xml file, you have essentially created 10 JNDI datasources with a total of 500 connections to your database and have likely completely overwhelmed your database. If you want to add a datasource to a single application, by remembering to create the datasource in the application level context.xml file, you can avoid serious performance problems.

Creating a Single Global Datasource for Application Sharing

Occasionally companies will deploy 3 or 4 related applications on a Tomcat server that are designed to share a single datasource. As described above, placing the datasource definition either once in the global context.xml file or in 3 or 4 application specific context.xml files will always create multiple instances of that datasource. To truly share a single datasource, it is necessary to put the definition of the datasource into the server.xml file, and then place a single resource link into the global context.xml file. This link ensures only one instance of the datasource is ever created and when any application goes to use it, it always uses the same single instance.

Optimizing Garbage Collection with Heap

In an ideal world, system administrators want three things: small heap sizes; small GC pauses and high throughput. In the real world, you get to pick any two of those but you have to sacrifice the third to get them. So if you want small GC pauses and high throughout, the price you have to pay for that is a large heap. This observation normally triggers questions about the optimum size for the Java object heap. The optimum size will vary from application to application but it is typically 4 to 5 times the minimum heap required by the application. To find the minimum heap size, look at the heap usage graphs for the application once it has reached steady state and the minimum heap required is the size the heap usage drops to just after a full garbage collection.

Developing and Deploying on Multiple Servlet Containers

While it would be ideal to standardize your entire web application stack on one servlet container, the reality is that many organizations use a variety of application servers. In the case where developers are writing the applications on Tomcat, and they may not be deployed on Tomcat, they can avoid future cross-compatibility issues by setting the system property for StrictServletCompliance. This property changes a series of system defaults to follow the servlet specification very strictly to ensure portability. For more information on configuring StrictServletCompliance  see the official documentation.

Mark Thomas is a Senior Software Engineer for the SpringSource Division of VMware, Inc. (NYSE: VMW). Mark has been using and developing Tomcat for over six years. He first got involved in the development of Tomcat when he needed better control over the SSL configuration than was available at the time. After fixing that first bug, he started working his way through the remaining Tomcat bugs and is still going. Along the way Mark has become a Tomcat committer and PMC member, volunteered to be the Tomcat 4 & 7 release manager, created the Tomcat security pages, become a member of the ASF and joined the Apache Security Committee. He also helps maintain the ASF's Bugzilla instances. Mark has a MEng in Electronic and Electrical Engineering from the University of Birmingham, United Kingdom.


What do you mean?

Why do you say that the ideal HEAP size is typically 4 to 5 times the minimum heap required by the application? Could you explain?
Would not it be better to say more HEAP better?

Fernando Franzini - Java Blog

how to declare datasource elegantly in Tomcat


Nice posts. Thanks for sharing.

However, I still don't know how to create a DB pool in Tomcat elegantly. Let me explain,

I have 3 Spring3-powered applications running on a Tomcat7 server. Each application need to access different databases and consequently access different DB pools.

I initially created the pools in context.xml. Unfortunately, as you mentioned, the pools were created for each application. This is not good as this opened useless connections.

I then created the pools in 3 separate application context.xml files, for each application. This looked like the best solution as each pool was created according to each application's needs. Unfortunately, each time an application is undeployed (e.g to install a new version) the application context.xml is removed by Tomcat. As far as I known, this is not possible to avoid this behavior. Am I right? In production environment, this solution is not really elegant (I can't ask the people in production to keep a backup of the application context.xml file and copy it each time I deploy a new version of my application).

What is the best way to go then ? Should I create the pools in server.xml and create links in context.xml?



something similar to StrictServletCompliance for Java?

I found that suggestion for tomcat really valuable, however one issue I get is apps that have been developed on tomcat running on oracle sdk, that fail when deployed to tomcat7 running on openjdk.

are there any similar strategies for enforcing use of only standards compliant java?

connections does not returned to pool.I am using DB2 9.1

connections does not returned to the pool,the size of the connection pool increases more than the maxSize.I am using the DB2 9.1 and tomcat 7.0.47.
I have configure the tomcat by changing the web.xml,context.xml and server.xml(which are at the conf directry).the configurations are as follows

DB2 Datasource example




hungry shark evolution hack android Cool you write, the information is very good and interesting, I'll give you a link to my site. clash of clans android hack

The optimum size will vary

The optimum size will vary from application to application but it is typically 4 to 5 times the minimum heap required by the application.

buy soundcloud followers

I would like to work with

I would like to work with this kind of websites. Every website is provides best australia assignment help writing books. So many people are using these all essay services and content writing books for us.

In Chanel Replica handbags

In Chanel Replica handbags accumulating every backpack has two variants of altered size. Prada Fair Accoutrements are ablaze of course: there are white, green, pink, red and dejected handbags. The ablaze apple of Prada Fair Accoutrements is a abundant allurement and a present for all Prada Replica handbags fans.Few capital stuffs that all women will accept got in their armoires will be clothing, shoes and rings. There are aswell a abundant abounding added accessories that adult women would ambition to accept in adjustment to enhance their looks and style. These fashionable females, who not alone accord accent to their clothes and shoes, but aswell admiration Replica Handbags uk accessories an important area of admonishment themselves, access an bend aloft all added girls.

Truly, this article is really

Truly, this article is really one of the very best in the history of articles. I am a antique ’Article’ collector and I sometimes read some new articles if I find them interesting. And I found this one pretty fascinating and it should go into my collection. Very good work! Text Your Ex Back pdf

Post new comment

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