I want to know how to run more than one application under one VM. I
am developing some Java servers, but I don't want 10 JVMs running when
only one is necessary. Is there a solution to this?
One approach at your disposal is to create a server process whose only
job is to load Java classes and execute their main() methods in a
The problem with doing this is that you do not benefit from the separation of address spaces and process contexts that you get from using separate JVMs. If one application thread terminates the application with an errant System.exit(0) or throws a fatal RuntimeException, all your applications will die. In addition, each application will share the same ClassLoader unless you explicitly force each to use a different ClassLoader.
You will want to use a different ClassLoader for each application, otherwise you will run
into problems where applications sharing global state in the form of static variables. Any attempt to share a single JVM between multiple Java applications will in effect lead to implementing your own application server. You could investigate the possibility of using
on of the many available application servers or possibly restructure your applications in the form of servlets.