RMI中实例化的存根在哪里

Where is the stub instantiated in RMI

我不确定远程对象存根实例的创建位置。是调用Naming.bind注册到rmiregistry时创建的吗?这是有道理的,因为注册表也是通过 RMI 调用的。

但是不能通过调用UnicastRemoteObject.exportObject创建存根吗?

这个特定的代码片段 from oracle 让我感到困惑:

Compute engine = new ComputeEngine();
Compute stub = (Compute) UnicastRemoteObject.exportObject(engine, 0);
String name = "Compute";
Registry registry = LocateRegistry.getRegistry();
registry.rebind(name, stub);

使用 Naming.bind 时,我需要传递存根或远程对象吗?

存根是

  1. 导出远程对象时创建
  2. 当您将远程对象作为远程方法参数或结果传递时替换远程对象,例如在注册表中绑定或查找时。

When using Naming.bind() do I need to pass a stub or a remote object?

要么。没关系,因为(2).