I. The principle of RMI operation
The nature of RMI is to implement calls between different JVMs, and it is implemented by opening a stub and skeleton in two JVMs, both of which are passed through the socket communication to implement parameters and return values.
The RMI example code can be found on the internet a lot, but most are through the extend the interface Java.rmi.Remote implementation, has been encapsulated very perfect, unavoidably make people have a sense of smoke and mirrors. The following example is what I see in "Enterprise JavaBeans", although it is very rough but intuitive and helps to understand how quickly it works.
1, define a person's interface, which has two business method, Getage () and GetName ()
Code:
public interface Person {
public int getAge() throws Throwable;
public String getName() throws Throwable;
}
2, person's realization Personserver class
Code:
public class PersonServer implements Person {
int age;
String name;
public PersonServer(String name, int age) {
this.age = age;
this.name = name;
}
public int getAge() {
return age;
}
public String getName() {
return name;
}
}