How to run a java file/project in remote JVM which is present in other Network?
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(local开发者_StackOverflowly), 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
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
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.
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...
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.)
精彩评论