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

查看:27
本文介绍了为什么每个应用程序有一个 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?

我说的是通过公共静态 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天全站免登陆