理解RMI的关键点

在学习RMI的过程中,对于RMI package的设计思想产生了兴趣
我在javaeye上发了一个帖子,但是没有人理我,只能自己研究了

http://www.javaeye.com/post/142161

Question:

java.rmi.Remote是一个interface,没有定义任何方法
  1. 为何在开发RMI程序时必须要extends Remote接口呢?(这是一种设计模式:Marker interface,详见blog专题)
  2. 为何在实现类的时候要extends UnicastRemoteObject呢?(继承UnicastRemoteObject类是为了连接到RMI系统,但是继承这个类不是必须的,一个类如果不继承UnicastRemoteObject也可以使用UnicastRemoteObject的exportObject()方法来连接到RMI系统)
  3. RMI的底层通信部分应该也是利用Socket吧,是否是通过extends UnicastRemoteObject来实现的?
  4. 在RMI中使用的是怎样的一种design pattern?(多种design pattern,有marker interface、proxy pattern)

Answer:

the key to understanding RMI is to remember that interfaces define behavior and classes define implementation.

在客户端程序中,只要定义接口就可以了;

服务器端负责具体的接口实现;

Remember that a Java interface does not contain executable code. RMI supports two classes that implement the same interface. The first class is the implementation of the behavior, and it runs on the server. The second class acts as a proxy for the remote service and it runs on the client.

A client program makes method calls on the proxy object, RMI sends the request to the remote JVM, and forwards it to the implementation. Any return values provided by the implementation are sent back to the proxy and then to the client's program.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值