Java RMI - UnicastRemoteObject: what is the difference between UnicastRemoteObject.exportObject() and extends UnicastRemoteObject?

后端 未结 4 1584
暖寄归人
暖寄归人 2021-02-05 08:46

i\'m preparing for an exam and I\'m having a question that I hope someone here could answer me.

It\'s about RMI and remote objects. I wonder why there is so much differe

相关标签:
4条回答
  • 2021-02-05 09:31

    Firstly, binding & rebinding remote object using Naming class and Registry class is not relevant to scenarios of whether or not a class is extending UnicastRemoteObject. See here for the differences.

    Secondly, the difference between the class extending UnicastRemoteObject is that if the object of that type is used as a stub, then you'll not need to call UnicastRemoteObject.exportObject to obtain the stub anymore for binding with registry. In your version 1, the StorehouseImpl must have extended the UnicastRemoteObject, and in fact, there's no need for EchoImpl to extend UnicastRemoteObject for your version 1 as there is no instance of EchoImpl is registered as a remote object to the registry.

    Thirdly, you mention what'd happen if rebind is executed without bind is executed beforehand. As explained in the javadoc here, if no key name has been inserted, it will behave in the same way as if first time bind is executed.

    0 讨论(0)
  • 2021-02-05 09:32

    java.rmi.server.UnicastRemoteObject is used for exporting a remote object with Java Remote Method Protocol (JRMP) and obtaining a stub that communicates to the remote object.

    For the constructors and static exportObject methods below, the stub for a remote object being exported is obtained ...

    There you should follow the Javadoc

    0 讨论(0)
  • 2021-02-05 09:33

    You can call the UnicastRemoteObject.exportObject() instead of extending the UnicastRemoteObject in a scenario where you need to extend any other class. Overall effect is the same I think.

    See this

    0 讨论(0)
  • 2021-02-05 09:42

    There are two questions here.

    1. You can either extend UnicastRemoteObject or call UnicastRemoteObject.exportObject(). Which you do is up to you. The first is simple and automatic; the second means you can extend another class.

    2. You can either use an external RMI Registry or create it yourself inside your server JVM. Again which you do is up to you, there are advantages both ways.

      These two questions have no interaction.

    3. If you extend UnicastRemoteObject you also get the benefit of 'remote semantics' for the hashCode() and equals() methods, such that all stubs appear to be identical to the remote object that exported them, but this is of no practical use on the client side, and is really only there to support the RMI implementation itself.

    0 讨论(0)
提交回复
热议问题