Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Java
Expertise: Beginner
Jan 18, 2000



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Multiple Applications Running On One JVM

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 separate thread.

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.

DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date