我了解到每个应用程序都在其自己的 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:
简而言之,有很多问题.人们一直在努力完成这项工作,但他们从未真正成功过.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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!