为什么每个应用程序有一个JVM? [英] Why have one JVM per application?

查看:763
本文介绍了为什么每个应用程序有一个JVM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读到每个应用程序都在自己的JVM中运行。为什么会这样?为什么他们不让一个JVM运行2个或更多个应用程序?

I read that each application runs in its own JVM. Why is it so ? Why don't they make one JVM run 2 or more apps ?

我读了一篇SO帖子,但无法在那里得到答案。
每个Java应用程序是否有一个JVM?

I read a SO post, but could not get the answers there. Is there one JVM per Java application?


我说的是通过public static void main(String [])方法启动的应用程序......)

I am talking about applications launched via a public static void main(String[]) method ...)

推荐答案

(我假设您正在讨论通过 public static void main(String [])方法启动的应用程序...)

(I assume you are talking about applications launched via a public static void main(String[]) method ...)

理论上,您可以在JVM中运行多个应用程序。在实践中,它们可以以各种方式相互干扰。例如:

In theory you can run multiple applications in a JVM. In practice, they can interfere with each other in various ways. For example:


  • JVM有一组System.in/out/err,一个默认编码,一个默认语言环境,一组系统属性等。如果一个应用程序更改了这些,它会影响所有应用程序。

  • 任何调用System.exit()的应用程序都会杀死所有应用程序。

  • 如果一个应用程序线程变得狂野,消耗太多CPU或内存也会影响其他应用程序。

总之,有很多问题。人们努力做到这一点,但他们从未真正成功过。一个例子是 Echidna 图书馆,尽管这个项目已经安静了大约10年。 JNode 是另一个例子,尽管他们(实际上我们)通过破解核心Java类(如java.lang.System)来欺骗这样每个应用程序都可以获得看似独立版本的System.in/out/err,系统属性等等 1

In short, there are lots of problems. People have tried hard to make this work, but they have never really succeeded. One example is the Echidna library, though that project has been quiet for ~10 years. JNode is another example, though they (actually we) "cheated" by hacking core Java classes (like java.lang.System) so that each application got what appeared to be independent versions of System.in/out/err, the System properties and so on1.

1 - 这个(proclets)应该是一个临时的黑客,等待使用真正的隔离的正确解决方案。但是隔离支持停滞不前,主要是因为JNode架构使用单个地址空间而没有明显的方法来分离系统和用户的东西。因此,虽然我们可以创建与隔离API匹配的API,但密钥隔离功能(如干净地杀死隔离区)实际上是不可能实现的。或者至少,这是我的观点。

这篇关于为什么每个应用程序有一个JVM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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