How do you run multiple JVMs on a single machine? How do you call methods in a different JVM?
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).
This doens't make any sense.
It's easy to install different JVMs, just install the various JREs, JDKs, etc.
To execute the different one, you would use the proper java command from each install. Many projects rely on JAVA_HOME for this setting.
If you're talking about multiple JVMs in a browser for applets, I can't help you.
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.).
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
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
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.
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.
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.