Optimizing Tomcat for Web applications

Learn how to make Tomcat run faster and handle more of a data load, thereby allowing increased performance of the development of your Web application.

WebSphere has gained significant market share in Web application development space. But there's a powerful, easy-to-use and free alternative to WebSphere -- Apache's Tomcat. Tomcat is open source and is the reference implementation for Sun Microsystems' servlet standard. Tomcat has proven itself as production quality and is used by many companies. Tomcat installation on Windows servers is an automated and easy process; however, the...

default installation places Tomcat into development mode. The advantage of development mode is that changes to JSPs, class, and JAR files are automatically incorporated at runtime without the need to restart the application server. The drawback is that performance suffers in development mode. Once an application is ready for production, the following steps should be taken to optimize Tomcat. 


1. Increase the maximum memory available:

Tomcat ships with the maximum amount of memory set to 64MB, which is not large enough to operate most large web applications. We recommend increasing the maximum amount of memory to 80% of the total RAM available on your server. This can be done as shown below. First, open Tomcat by going to the Start Menu-Programs-Apache Tomcat-Start Tomcat.


After Tomcat has started you should see the Tomcat icon in the lower right-hand corner, as shown below.

To access the Tomcat properties allowing changes to the maximum memory, right click on the icon and select properties. This is also the way to stop the server by clicking on Shutdown: Tomcat instead of properties.

The properties screen below has the Java VM tab selected. Inside the Java Options is where we are going to add some information by going to add the increased min and max memory allocation.

The minimum value can be anything but should start with at least 64-100 MB. The maximum memory should be up to 80% of your computer's RAM. For example, if you have 512 MB of RAM, then you should set the maximum memory to around 400 MB. We are also going to add a server tag that basically tells the compiler that when it's running, it is running as a server. It changes its optimization strategy of the just-in-time compiler. To do this, you need to add this code to the Java Options text area:

-Xms100m -Xmx400m


Now we have changed the default memory allocation for Tomcat to handle heavier data loads. However, there are still a few more changes we can make to improve speed and efficiency.

Changes to web.xml configuration file:

The web.xml is the document that defines default values for *all* Web applications loaded into each instance of Tomcat. As each application is deployed, this file is processed, followed by the "/WEB-INF/web.xml" deployment descriptor from your own applications. The web.xml is located in Apache Software Foundation-Tomcat-conf folder shown below.

Open the web.xml by right clicking and selecting open with (NotePad, Wordpad or any text editor). Now, in the document we want to find the JSP Servlet Tag. This is located a quarter of the way down the page. Add two initial parameters -- the reloading parameter and the development parameter.

The reloading and development parameters are automatically set to true when Tomcat is installed. The development init-parameter will check for JSP modification on every access and reload. Set both of these parameters in the web.xml document to false so Tomcat will not look for or reload changes to JSPs on every access.

To add the init-parameters you will add this code:


In summary, Tomcat is a cost-efficient tool to hosting Web applications. Now that you have made the above simple changes, Tomcat will run much faster and handle more of a data load, allowing increased performance of the development of your Web application. Tomcat also has its own administration, which can be helpful and accessed through the Tomcat Web site.

About the author: Paul Holm is a former IBM-Rochester WebSphere, Java, and DB2 developer/consultant. He specializes in helping iSeries RPG shops develop Web-based applications. Paul is currently a lead architect for the "WOW" product, which is Query/400 and DFU for WebSphere (aka WebSphere on steriods). Paul can be reached at pholm@planetjavainc.com.


This was first published in August 2004

Dig deeper on Web Development



Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: