JAVA RMI远程调用demo

来源:互联网 发布:黑客用什么系统 知乎 编辑:程序博客网 时间:2024/05/10 17:29

1 创建接口继承 Remote

The Remote interface serves to identify interfaces whose methods may be invoked from a non-local virtual machine. Any object that is a remote object must directly or indirectly implement this interface. Only those methods specified in a "remote interface", an interface that extends java.rmi.Remote are available remotely

Implementation classes can implement any number of remote interfaces and can extend other remote implementation classes. RMI provides some convenience classes that remote object implementations can extend which facilitate remote object creation. These classes are java.rmi.server.UnicastRemoteObject and java.rmi.activation.Activatable

Rmote 这个接口是一个标记接口,用来标记一个类的方法可以被非本地的java虚拟机调用。所有的远程调用对象必须直接或间接实现这个接口,只有集成实现了Rmote接口才能被远程调用。

实现类可以实现任意多个远程调用接口,或者继承其他的实现了远程接口的实例。RMI提供了一些辅助类,来帮助创建远程调用类

java.rmi.server.UnicastRemoteObject

UnicastRemoteObject extends RemoteServer

RemoteServer extends RemoteObject

RemoteObject implements Remote, java.io.Serializable

Used for exporting a remote object with JRMP and obtaining a stub that communicates to the remote object. Stubs are either generated at runtime using dynamic proxy objects, or they are generated statically at build time, typically using the rmic tool. 

java.rmi.activation.Activatable.

The Activatable class provides support for remote objects that require persistent access over time and that can be activated by the system.

For the constructors and static exportObject methods, the stub for a remote object being exported is obtained as described injava.rmi.server.UnicastRemoteObject.  

Activatable extends RemoteServer


//占位 后续补充


0 0