Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
102 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...