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

自古美人都是妖i 提交于 2019-12-18 13:01:45

问题


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

In my application I am using Registry class. But I want to know about Naming class and its uses ?


回答1:


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.



来源:https://stackoverflow.com/questions/3630329/difference-between-classes-java-rmi-registry-registry-and-java-rmi-naming

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!