13

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

z -
  • 7,130
  • 3
  • 40
  • 68
giri
  • 26,773
  • 63
  • 143
  • 176
  • @yx: I'm not sure, but I think the original question was about how to "communicate" between two Java processes running in different VMs. – Peter Lang Jan 08 '10 at 19:52
  • maybe I misread it, I've edited my edit, I absolutely had to get rid of the horrid grammar: "Is dat pssible" so I might have done it a bit too fast :( – z - Jan 08 '10 at 19:53
  • Please explain what you want to achieve. This question is way to open to interpretation; you won't get any useful answer like this. – extraneon Jan 08 '10 at 20:00
  • If you want close communication between these components, you could have one JVM which contains everything you need. If you want to be able to load different modules independently, you could look at an OSGI container. – Peter Lawrey Jan 09 '10 at 13:42
  • "multiple JVMs" : do you mean multiple instances of a jvm or different jvm? – Shirish Herwade Feb 12 '13 at 07:04

9 Answers9

22

How do you run multiple JVMs on a single machine?

Just launch multiple java processes.

How do you call methods in a different JVM?

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

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
10

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

scienty
  • 314
  • 1
  • 3
6

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

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:

$PATH_TO_FIRST_JVM/bin/java -jar application1.jar
$PATH_TO_DIFFERNT_JVM/bin/java -jar application2.jar
Jason Nichols
  • 11,603
  • 5
  • 34
  • 53
6

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.

and regarding calling a method u can use RMI.

GuruKulki
  • 25,776
  • 50
  • 140
  • 201
5

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

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).

TofuBeer
  • 60,850
  • 18
  • 118
  • 163
  • also see sun's online training on RMI: http://java.sun.com/developer/onlineTraining/rmi/RMI.html – z - Jan 08 '10 at 19:52
  • If your need to communicate between multiple JVMs, use UdpInvoker http://code.google.com/p/udp-invoker/. – Eflite Oct 11 '11 at 15:26
2

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.

Will Hartung
  • 115,893
  • 19
  • 128
  • 203
2

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.

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.

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.

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
2

How do you run multiple JVMs on a single machine? How do you call methods in a different 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.

RubyNuby
  • 21
  • 1
-1

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.

Steve Wall
  • 1,842
  • 5
  • 21
  • 50