Difference between classes java.rmi.registry.Registry and java.rmi.Naming

后端 未结 1 395
逝去的感伤
逝去的感伤 2020-12-31 10:15

What is the difference between the Registry class and Naming class.

In my application I am using Registry class. But I want to

1条回答
  •  悲&欢浪女
    2020-12-31 10:58

    The difference is that Naming is a utility class with static methods, while Registry is a remote interface. Unsurprisingly, Naming calls Registry internally. Note that the name arguments you pass to java.rmi.Naming are in URL format, and include the location of the registry, whereas with java.rmi.registry.Registry, the name is just the name.

    For example, you would call something like this:

    Naming.rebind("//host/objName", myObj);
    

    whereas with Registry, you need an existing handle on the registry object, and you'd call:

    Registry registry = LocateRegistry.getRegistry("host");
    registry.rebind("objName", myObj);
    

    So Naming is really just a convenience class that saves you having to look up the Registry manually - it performs the registry lookup and rebind in one step.

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