java JVM 实例
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3652353/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Instances of JVM
提问by JavaUser
Does invoking java via two different command line involves two different JVMs or two separate instances of same JVM.
通过两个不同的命令行调用 java 是否涉及两个不同的 JVM 或同一 JVM 的两个单独实例。
回答by helios
JVM is Java Virtual Machine, a memory space where classes (code) are loaded and objects (data) are shared. JVM is equivalent to an Operating System process.
JVM 是 Java 虚拟机,一个加载类(代码)和共享对象(数据)的内存空间。JVM 相当于一个操作系统进程。
When you type java...
in you command line you are executing an independent process that loads Java classes in memory, the base classes from Java and yours (from the .class files or .jar you indicate).
当您java...
在命令行中键入时,您正在执行一个独立的过程,该过程将 Java 类加载到内存中,即来自 Java 的基类和您的基类(来自您指定的 .class 文件或 .jar)。
Another java...
command will load a different process with its own memory and will load classes by itself.
另一个java...
命令将使用自己的内存加载不同的进程,并将自行加载类。
Instance word confusion: when you say 'two instances of the same JVM'. It's usual to say instance of a JVM to a separate process, it is, to a loaded independent JVM. If you are saying: two process are running JVM 1.5, OK, it's the same JVM in the sense it's the same version but they are different processes, different 'instances', independent in all sense.
实例词混淆:当您说“同一 JVM 的两个实例”时。通常将 JVM 的实例称为单独的进程,即加载的独立 JVM。如果你说:两个进程正在运行 JVM 1.5,好吧,它是同一个 JVM,因为它是相同的版本,但它们是不同的进程,不同的“实例”,在所有意义上都是独立的。
Webapp confusion:A webapp (by example) is simply a bunch of classes and objects instantiated, attending some URL in a web server. You can start Tomcat with 10 different apps -it is, 10 different bunches of classes and objects each of them attending different request, but in fact they share the same memory space (OS process). A webapp cannot touch other webapp's objects because nobody gives it a reference to the other objects (and classes are in some way hidden but that's another story called: class-loading).
Webapp 混淆:一个 webapp(通过示例)只是一堆实例化的类和对象,参与 Web 服务器中的某个 URL。您可以使用 10 个不同的应用程序启动 Tomcat - 它是 10 组不同的类和对象,每个类和对象都处理不同的请求,但实际上它们共享相同的内存空间(操作系统进程)。一个 webapp 不能接触其他 webapp 的对象,因为没有人给它一个对其他对象的引用(类在某种程度上是隐藏的,但这是另一个故事:类加载)。
回答by splash
What is the difference in your question? I would say: two different JVM instances. :)
你的问题有什么不同?我会说:两个不同的 JVM 实例。:)
Each run of the the java
command does invoke a new JVM instance. The running java application could run new Java Threads (like a Tomcat does with web applications).
该java
命令的每次运行都会调用一个新的 JVM 实例。正在运行的 Java 应用程序可以运行新的 Java 线程(就像 Tomcat 对 Web 应用程序所做的那样)。
回答by bwawok
Two separate JVMs. You can run lots of stuff inside the same JVM (say 10 webapps served up by the same Tomcat instance), but there is only 1 java command to start tomcat.
两个独立的 JVM。您可以在同一个 JVM 中运行很多东西(比如由同一个 Tomcat 实例提供的 10 个 webapps),但是只有 1 个 java 命令来启动 tomcat。
回答by Paul Gregtheitroade
If you started Sun's java.exe from their JDK/JRE version 1.6 from the same source path twice, you would get two separate and distinct JVM instances. There would be no sharing between them unless you configured it via your applications. If you wanted two different JVM's running you would have to start a java.exe of one type (say 1.5) from one location and a java.exe (version 1.6) from another.
如果您从相同的源路径两次从其 JDK/JRE 1.6 版启动 Sun 的 java.exe,您将获得两个独立且不同的 JVM 实例。除非您通过应用程序对其进行配置,否则它们之间不会共享。如果您想要运行两个不同的 JVM,您必须从一个位置启动一个类型(比如 1.5)的 java.exe,从另一个位置启动一个 java.exe(版本 1.6)。