Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible for a JVM to run more than one program at the same time?

Tags:

java

jvm

Is it possible for a JVM to run more than one program at the same time? If so, how? If not, why?

To run a program, we simply do

java ProgramName

But can we use the same JVM instance to run another program?

like image 802
CodeBlue Avatar asked Apr 25 '13 17:04

CodeBlue


1 Answers

The answer depends on your definition of "program." The Java programs that have a main method and that you start with java NameOfClass typically cannot be run in the same JVM because there's no builtin separation of resources or namespaces. For example, what if the two programs use conflicting versions of the same library?

We also have applications that are designed to share a JVM, such as enterprise applications. These are programs that are designed to run in the context of an "application server", which is basically a program for running other programs. An application server keeps the applications resources separate using classloaders and security managers. For example, two applications may use conflicting versions of a library or conflicting class names and still share a JVM thanks to being loaded through different classloaders.

like image 74
Joni Avatar answered Sep 30 '22 20:09

Joni