Java 我可以在一台 PC 上运行多个 JVM 吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1986531/
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
can I run more than one JVM on my single PC?
提问by giri
Can I run more than one JVM? If yes then how can I find a particular class is loaded on which JVM?
我可以运行多个 JVM 吗?如果是,那么如何找到特定类加载到哪个 JVM 上?
采纳答案by Jon Skeet
It's not entirely clear what you mean, but:
您的意思并不完全清楚,但是:
- You can have more than one VM (version / brand etc) installed on the same machine
- You can run more than one
java
process, whether of the same JVM version or different ones
- 您可以在同一台机器上安装多个 VM(版本/品牌等)
- 您可以运行多个
java
进程,无论是相同的 JVM 版本还是不同的
Unless you're running a debugging agent or something similar, I don't know of any way to ask a JVM process whether it's loaded a particular class. It seems a bit of an odd requirement - why do you want to do this?
除非您正在运行调试代理或类似的东西,否则我不知道有什么方法可以询问 JVM 进程是否加载了特定的类。这似乎是一个奇怪的要求——你为什么要这样做?
回答by Carl Smotricz
You can run as many JVMs as you can fit on your disk and in memory :)
您可以在磁盘和内存中运行尽可能多的 JVM :)
Whenever you start a Java application, you're first starting the JVM and then telling it which application to run. The answer to "which JVM" is simply: The JVM that you loaded the application with!
每当您启动 Java 应用程序时,您首先要启动 JVM,然后告诉它要运行哪个应用程序。“哪个 JVM”的答案很简单:您加载应用程序的 JVM!
It's possible to do some esoteric fiddling with classloaders which would prove an exception to what I've just said. But it's true in the general case and the majority of all applications.
可以对类加载器进行一些深奥的摆弄,这将证明我刚才所说的除外。但在一般情况下和大多数应用程序中都是如此。
回答by JCasso
Multiple JRE(Java Runtime Enviroment) is very possible. I do so. The thing is JVM does not always run on your system. It is like any other software. When you run a jar file, it starts running.
多个JRE(Java 运行时环境)是非常可能的。我这样做。问题是 JVM 并不总是在您的系统上运行。它就像任何其他软件一样。当您运行 jar 文件时,它就会开始运行。
The default JRE is set in Environment Variables as JAVA_HOME(right click my computer -> properties -> advanced tab -> Environment Variables)
默认JRE在Environment Variables中设置为JAVA_HOME(右键我的电脑->属性->高级选项卡->环境变量)
To run a jar file you simply run this command:
要运行 jar 文件,您只需运行以下命令:
C:\Program Files\Java\j2re1.4.2_04\bin\javaw.exe" -jar Myfile.jar
C:\Program Files\Java\j2re1.4.2_04\bin\javaw.exe" -jar Myfile.jar
You can use any other jre javaw to run a jar file.
您可以使用任何其他 jre javaw 来运行 jar 文件。
Please note that j2re1.4.2_04 may not be your jre version.
请注意 j2re1.4.2_04 可能不是您的 jre 版本。
Edit:
编辑:
All classes in a jar file run on a single JVM. As you may guess. See your JAVA_HOME, it is the default.
jar 文件中的所有类都在单个 JVM 上运行。正如你可能猜到的。看你的JAVA_HOME,它是默认的。
回答by emeraldjava
Can I run more than one JVM?
我可以运行多个 JVM 吗?
Yes - just run the 'java' process
是的 - 只需运行“java”进程
If yes then how can I find a particular class is loaded on which JVM?
如果是,那么如何找到特定类加载到哪个 JVM 上?
The 'jps' program that is distributed with the JAVA SDK will list all java processes (JVM's) ruinning on your machine, the main class that is being executed by each JVM and the classpath. You'll have to see which jars or classes are on each classpath to figure out if a class is loaded or not.
与 JAVA SDK 一起分发的“jps”程序将列出您机器上的所有 Java 进程 (JVM)、每个 JVM 正在执行的主类和类路径。您必须查看每个类路径上有哪些 jar 或类才能确定类是否已加载。
try running
尝试跑步
jps -mlvV
and see what you get
看看你得到了什么
回答by Upgradingdave
Yes, you can run multiple JVM's on a single machine.
是的,您可以在一台机器上运行多个 JVM。
Sun packages the tools to run the jvm in a few different ways. Usually, you either have a java development kit (jdk) or java standard edition (jse) installed as the default. Those packages include a java
program that gets invoked to start a jvm. In addition, the jdk also contains some additional commands (like javac
) for developers.
Sun 打包了以几种不同方式运行 jvm 的工具。通常,您默认安装了 Java 开发工具包 (jdk) 或 Java 标准版 (jse)。这些包包括一个java
被调用以启动 jvm 的程序。此外,jdk 还包含一些额外的命令(如javac
)供开发人员使用。
You can have multiple jdk's and or jse's available on a single machine. On windows, jdk and jse packages are usually installed under Program Files/java
(this is from memory as I don't have a pc handy at the moment)
您可以在一台机器上使用多个 jdk 和/或 jse。在 Windows 上,jdk 和 jse 包通常安装在Program Files/java
(这是从内存中安装的,因为我现在手头没有电脑)
On Mac look under /System/Library/Frameworks/JavaVM.framework/Versions.
在 Mac 上查看 /System/Library/Frameworks/JavaVM.framework/Versions。
On Linux, I would use which java
command to determine where the default java
command is installed (usually /usr/bin). Then do a ls -al | grep java
(inside /usr/bin, for example) and note where the symlinks point in order to figure out where there might be other versions installed.
在 Linux 上,我会使用which java
command 来确定默认java
命令的安装位置(通常是 /usr/bin)。然后执行ls -al | grep java
(例如在 /usr/bin 中)并注意符号链接指向的位置,以便找出可能安装了其他版本的位置。
Once you've figured out where each of the various jdk's and jse's are located on your system, then you can start to figure out which version of java is used to start each of the programs.
一旦确定了各种 jdk 和 jse 在系统上的位置,就可以开始确定使用哪个版本的 java 来启动每个程序。
Each java program will startup using the default jvm. Open a command window or terminal and try java -version
to determine which version is the current default.
每个 java 程序都会使用默认的 jvm 启动。打开命令窗口或终端并尝试java -version
确定当前默认版本是哪个版本。
Rather than using the default java version, programs can also be started to use a specific java version. For example, sometimes I create a custom windows shortcut to open Eclipse using a specific version of the jdk.
除了使用默认的 java 版本之外,还可以启动程序以使用特定的 java 版本。例如,有时我会创建一个自定义的 Windows 快捷方式来使用特定版本的 jdk 打开 Eclipse。
As of java 5, there's a tool named jconsolethat might also help you determine which programs are running in which verions of jvms. Simply open a console, and type jconsole
and you should get a nice GUI that shows all the programs running in the default jvm. I think you might even be able to inspect programs classpaths.
从 java 5 开始,有一个名为jconsole的工具也可以帮助您确定哪些程序在哪些 jvm 版本中运行。只需打开一个控制台,然后键入jconsole
,您就会得到一个漂亮的 GUI,它显示了在默认 jvm 中运行的所有程序。我认为您甚至可以检查程序类路径。
Hope that helps, good luck!
希望能帮到你,祝你好运!
回答by kamal nayan
Yes,you can install more than one jvm in your PC, because OS loads an instance of jvm (not whole jvm) in RAM. We can call different jvm like JDK 1.4 or JDK 1.6 by setting its path.
是的,您可以在 PC 中安装多个 jvm,因为操作系统在 RAM 中加载了一个 jvm(而不是整个 jvm)实例。我们可以通过设置其路径来调用不同的 jvm,如 JDK 1.4 或 JDK 1.6。
回答by nrg
You can run as many as you wish JVM on the same machine. You just need to open several CommandPrompt windows and run what you want via java
or javaw
application. The class that each of the JVM is running is THAT class which contain the main()
method. Main() method is the first thing that runs when you start some Java app. Of course, main() is situated in some of your classes. That's all.
您可以在同一台机器上运行任意数量的 JVM。您只需要打开几个 CommandPrompt 窗口并通过java
或javaw
应用程序运行您想要的内容。每个 JVM 正在运行的类是包含该main()
方法的那个类。Main() 方法是您启动某个 Java 应用程序时首先运行的方法。当然, main() 位于您的某些类中。就这样。