Back

TechnologyNov 15, 2011

Parallel Deployment in Tomcat 7

Credera Team

A common practice when deploying a new version of your application is to drain current sessions, stop the server, deploy a new version, and restart the server.  I’m going to show you a simpler way using Tomcat 7. A new feature in this version gives us the flexibility to eliminate the previously-mentioned steps in favor of simply copying the new war to the server and letting the server manage which version the user sees.

Let’s take a look at a very simple web application archive named test1.war.  In this version, I simply have a page that says, “This is my web application (version 1).”  With autodeploy enabled (in <catalina_home>/conf/server.xml) and my server running, I can deploy my war with the following logged to the console:

Nov 15, 2011 12:54:35 PM org.apache.catalina.startup.HostConfig deployWAR INFO: Deploying web application archive test1.war

When I hit my web application I see:

Now I want to improve my web application and deploy the new version (again while Tomcat is running since autodeploy is enabled).  This time I add “##” and a String that will be greater than the previous version. My <catalina_home>/webapps folder looks like this:

When Tomcat deploys this version, all new sessions will be directed here and all previous sessions will continue to use the old version.

Nov 15, 2011 1:04:06 PM org.apache.catalina.startup.HostConfig deployWAR INFO: Deploying web application archive test1##2.war

When I hit my web application this time from the browser I used previously (with the existing session), I continue to see what I did before.  However, if I open a new browser (creating a new session), then I am directed to the new version of my web application.  This version is much better, don’t you think?

In the unlikely event that you need to revert your changes, you can simply copy your original application and rename it with a name that makes it the most recent application so that all new sessions would again be back on the original version.  If your enhanced version is really bad, then you can delete both the war and exploded directory and immediately send all users back to the original version.

You can see the power of this as I never had to stop the server or remove a version that users are currently using to deploy my new version.  Yet another reason to upgrade to Tomcat 7!

Tomcat 7 documentation on the subject can be found here:

Tomcat 7 – Parallel Deployment Documentation