Java 运行多个JVM

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2030255/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 02:47:57  来源:igfitidea点击:

Running multiple JVMs

javajvm

提问by giri

How do you run multiple JVMs on a single machine? How do you call methods in a different JVM?

如何在一台机器上运行多个 JVM?如何在不同的 JVM 中调用方法?

采纳答案by Pascal Thivent

How do you run multiple JVMs on a single machine?

如何在一台机器上运行多个 JVM?

Just launch multiple javaprocesses.

只需启动多个java进程。

How do you call methods in a different JVM?

如何在不同的 JVM 中调用方法?

Use any type of RPC framework (RMI, EJB, web service, etc.).

使用任何类型的 RPC 框架(RMI、EJB、Web 服务等)。

回答by TofuBeer

Yes you can run multiple VMs on the same machine. You just need to specify which one to run.

是的,您可以在同一台机器上运行多个 VM。您只需要指定要运行哪个。

When you say you want to call methods running on different JVMs do you mean have them talk to each other? If so look at Remote Method Invocation (RMI).

当您说要调用在不同 JVM 上运行的方法时,您的意思是让它们相互通信吗?如果是这样,请查看远程方法调用 (RMI)

回答by Will Hartung

This doens't make any sense.

这没有任何意义。

  1. It's easy to install different JVMs, just install the various JREs, JDKs, etc.

  2. To execute the different one, you would use the proper java command from each install. Many projects rely on JAVA_HOME for this setting.

  3. If you're talking about multiple JVMs in a browser for applets, I can't help you.

  1. 安装不同的 JVM 很容易,只需安装各种 JRE、JDK 等。

  2. 要执行不同的命令,您将使用每个安装中正确的 java 命令。许多项目依赖 JAVA_HOME 进行此设置。

  3. 如果您在讨论小程序浏览器中的多个 JVM,我无能为力。

回答by scienty

Hey, I think you might be confused with how to run JVM. each execution of java.exe or javaw.exe will create a new instance of JVM for you. if you run two programs using two java.exe commands then you have two JVM's running

嘿,我想你可能对如何运行 JVM 感到困惑。每次执行 java.exe 或 javaw.exe 都会为您创建一个新的 JVM 实例。如果您使用两个 java.exe 命令运行两个程序,那么您有两个 JVM 正在运行

回答by Jason Nichols

It sounds like your talking about having different methods within a single application run under different JVMs. This is not possible.

这听起来像是您在谈论在不同 JVM 下运行的单个应用程序中使用不同的方法。这不可能。

If you want to use different JVMs for different applications, you'll have to manually specify the path to the particular JRE when you start an app. Example:

如果要为不同的应用程序使用不同的 JVM,则必须在启动应用程序时手动指定特定 JRE 的路径。例子:

$PATH_TO_FIRST_JVM/bin/java -jar application1.jar
$PATH_TO_DIFFERNT_JVM/bin/java -jar application2.jar

回答by GuruKulki

you can have as many jvm as you can running on a single machine as every java.exe or javaw.exe will star a new jvm.

您可以在一台机器上运行尽可能多的 jvm,因为每个 java.exe 或 javaw.exe 都会启动一个新的 jvm。

and regarding calling a method u can use RMI.

关于调用方法,您可以使用 RMI。

回答by Thorbj?rn Ravn Andersen

You can launch several java programs on the same machine (for example Eclipse is a java program, which can launch your program), but there is nothing providing easy communication between different JVM's.

您可以在同一台机器上启动多个 java 程序(例如 Eclipse 是一个 java 程序,它可以启动您的程序),但是没有什么可以在不同的 JVM 之间提供简单的通信。

RMI is the mechanism Sun provides to provide communication between JVM's on different or the same machine, but it is non-trivial to get to work correctly and have not emerged as the de-facto way to to this. An important facility is that it can move objects between JVM's even if the corresponding classes are not present in the target JVM.

RMI 是 Sun 提供的一种机制,用于在不同或同一台机器上提供 JVM 之间的通信,但要使其正常工作并非易事,而且还没有成为实现这一目标的实际方法。一个重要的功能是,即使目标 JVM 中不存在相应的类,它也可以在 JVM 之间移动对象。

http://java.sun.com/javase/technologies/core/basic/rmi/index.jsp

http://java.sun.com/javase/technologies/core/basic/rmi/index.jsp

Otherwise you may consider grid software, Terracotta, or any remote procedure call mechanism. These are usually TCP/IP based. You may want to edit your question to describe what you want to accomplish to get an idea how to get there.

否则,您可以考虑网格软件、Terracotta 或任何远程过程调用机制。这些通常是基于 TCP/IP 的。您可能想要编辑您的问题以描述您想要完成的任务,以了解如何到达那里。

回答by ptsw

There are several insightful answers here, but something that interests me the driving requirement for running multiple JVMs. Why do you believe you need to do this? If you are looking for parallel processing, you might want to consider a multi-threaded application as opposed to running multiple JVMs. Since each JVM could very likely require significant resources and you'd like to have communication between paths of execution, this may very likely be a better solution for your needs.

这里有几个有见地的答案,但让我感兴趣的是运行多个 JVM 的驱动要求。为什么你认为你需要这样做?如果您正在寻找并行处理,您可能需要考虑多线程应用程序,而不是运行多个 JVM。由于每个 JVM 很可能需要大量资源,并且您希望在执行路径之间进行通信,因此这很可能是满足您需求的更好解决方案。

回答by RubyNuby

How do you run multiple JVMs on a single machine? How do you call methods in a different JVM?

如何在一台机器上运行多个 JVM?如何在不同的 JVM 中调用方法?

RMI is how this is generally done. I also want to do the same thing but with out RMI. Easy way to get past the 1.5g ceiling on 32bit JVM's which on windows are the only ones that can play video (JMF + Fobs, VLCJ, GStreamer all fail with Oracles 64bit JVM, Harmony isnt ready yet, gave it a shot, wasn't pretty). Figured the video could run in another JVM and somehow share the objects probably via some JNI.

RMI 通常是这样做的。我也想做同样的事情,但没有 RMI。在 32 位 JVM 上突破 1.5g 上限的简单方法,在 Windows 上是唯一可以播放视频的(JMF + Fobs、VLCJ、GStreamer 在 Oracle 64 位 JVM 上都失败了,Harmony 还没有准备好,试一试,不是'漂亮)。认为视频可以在另一个 JVM 中运行,并可能通过某些 JNI 以某种方式共享对象。