JVM是否可以同时运行多个程序? [英] Is it possible for a JVM to run more than one program at the same time?

查看:1379
本文介绍了JVM是否可以同时运行多个程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

但是我们可以使用相同的JVM实例来运行另一个程序吗?

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

推荐答案

答案取决于你对程序的定义。具有方法并且以 java NameOfClass 开头的Java程序通常不能在同一个JVM中运行,因为没有内置的资源或命名空间分离。例如,如果两个程序使用相同库的冲突版本会怎样?

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?

我们还有用于共享JVM的应用程序,例如企业应用程序。这些程序设计为在应用程序服务器的上下文中运行,应用程序服务器基本上是用于运行其他程序的程序。应用程序服务器使用类加载器和安全管理器将应用程序资源分开。例如,两个应用程序可能使用库的冲突版本或冲突的类名,并且仍然可以共享JVM,这要归功于通过不同的类加载器加载。

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.

这篇关于JVM是否可以同时运行多个程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆