tags:

views:

214

answers:

4

I am trying to work on a project which involves running/executing the java file in three JVM on different Network. If i locally run the Java file should simultaneously should run in all three or two JVM.

For example :/usr/local/helloWorld.java

class HelloWorld {

    public static void main(String args[]){
         System.out.println("Hello World");
     }

   }

When i run this /usr/local/$java helloWorld This should print Hello World in JVM1(locally), JVM2(which is Remote) .

Is there way to say remote machine JVM2 that path for class file is located at /usr/local/ execute the file from there ?.

or

Should i run $java helloWorld in remote machine also ?

Thanks

A: 

To run commands on several JVM, I guess you'll need to implement some kind of client/server or P2P or multicast logic to send commands to the clients. To find "remote classes definitions", the clients could use an URLClassLoader to load classes and resources from a search path of URLs referring to both JAR files and directories.

(EDIT: I have no experience with it but maybe have a look at Jini. Not sure it will suit your needs though.)

Pascal Thivent
+1  A: 

From a pure Java perspective (vs. ssh'ing to the machine for remote shell instantiation), you may want to consider RMI and an Aglet pattern where an object can be network/jvm transparent and execute on any configured target.

Xepoch
@Xepoch RMI is object running in one Java virtual machine to invoke methods on an object running in another Java virtual machine. I am looking for something like if i instantiate an Object in One JVM should create another instance in remote JVM . and Aglet is more related to Mobile agent , i am looking for a desktop applicaiton atleast for now .
YetAnotherCoder
@Srinivas, RMI can be used to also transport the serializable object if you're target JVMs are not aware of the class. As mentioned before you can also use a URLClassLoader to roughly accomplish the same. Aglet's don't have to be for mobile use, "pattern" used commonly elsewhere. Parallel object instantiation is a very separate beast. e.g. do you want EVERY object to be new'd on every JVM in mirror fashion or just certain objects? If the former you may need to implement your own mmap/file heap, if the latter implement a proxy that employs RMI to new the object on target JVMs.
Xepoch
+1  A: 

Plain Java does not have the mechanism readily available to invoke and synchronize multiple JVM's on multiple machines.

I would suggest looking into a grid platform supporting Java or the Open Source version of Terracotta depending on what you need to do.

http://www.terracotta.org/web/display/orgsite/Home

Thorbjørn Ravn Andersen
A: 

Hello,

You may have a look at JGroups. Then you can implement your app in a way it won't start processing until enough 'group members' have joined and once all group members have joined you can use JGroups to let them communicate... But you will still have to start the JVMs manually or by a script...

pgras