File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Tomcat and the fly likes Two JVMs under one Tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Two JVMs under one Tomcat" Watch "Two JVMs under one Tomcat" New topic

Two JVMs under one Tomcat

Marcin Mogiela

Joined: Aug 30, 2007
Posts: 14

Is there a way to run two different applications on two different virtual machines running under the same tomcat server?

[ November 14, 2007: Message edited by: Marcin Mogiela ]

SCJP 5.0, SCWCD 1.4
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
Welcome to JavaRanch.

No. A Tomcat instance runs inside of a JVM, and so will all web apps deployed in it. You could start a second Tomcat instance (and thus a second JVM), but what is it that are you trying to achieve?
Marcin Mogiela

Joined: Aug 30, 2007
Posts: 14
Thanks for the quick response.

The application I work on uses a system property to get a path to a file with other configuration properties. It is very difficult to change existing behavior. The system property is set at the time of Tomcat startup.
I would like to have two instances of the application running under one server and the problem is that they share the same global system property.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
I wouldn't put application properties into the system properties anyway. Why not have a Properties object that is unique to a web application? That would solve this immediate problem, and also ensure that different web apps don;t step on each others toes.

It may not be feasible to implement in your case, but I wouldn't keep two web apps (no matter where they're running) that differ only in some configuration details, and otherwise use the same code. That calls for a client capability built into the web app itself, so that it's possible to have one web app that reacts in two or more different ways depending on who's accessing it.
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

That being said, there are times when it makes sense to have various applications isolated from one another and it is possible to run multiple copies of Tomcat on a single machine, even from the same Tomcat codebase.

This from the 4x documentation but I'm fairly sure the process is the same for current versions. I've done this with 5.0.28

(4) Advanced Configuration - Multiple Tomcat 4 Instances

In many circumstances, it is desirable to have a single copy of a Tomcat 4
binary distribution shared among multiple users on the same server. To make
this possible, you must configure a CATALINA_BASE environment variable (in
addition to CATALINA_HOME as described above) that points to a directory
that is unique to your instance.

When you do this, Tomcat 4 will calculate all relative references for files in
the following directories based on the value for CATALINA_BASE instead of

* conf - Server configuration files (including server.xml)

* logs - Log and output files

* shared - For classes and resources that must be shared across all web

* webapps - Automatically loaded web applications

* work - Temporary working directories for web applications

* temp - Directory used by the JVM for temporary files (

If you do not set CATALINA_BASE to an explicit value, it will be initialized
to the same value as is set for CATALINA_HOME (which means that the same
directory is used for all relative path resolutions).

The administration and manager web applications, which are defined in the
$CATALINA_BASE/webapps/admin.xml and $CATALINA_BASE/webapps/manager.xml will
not run in that configuration, unless either:
- The path specified in the docBase attribute of the Context element is made
absolute, and replaced respectively by $CATALINA_HOME/server/webapps/admin
and $CATALINA_HOME/server/webapps/manager
- Copying and linking both web applications in $CATALINA_BASE, and modify
accordingly the path specified in the docBase attribute of the Context
- Disabling both web applications by removing $CATALINA_BASE/webapps/admin.xml
and $CATALINA_BASE/webapps/manager.xml

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
I agree. Here's the link:
subject: Two JVMs under one Tomcat
It's not a secret anymore!