类java.rmi.registry.Registry和java.rmi.Naming之间的区别 [英] Difference between classes java.rmi.registry.Registry and java.rmi.Naming
问题描述
注册表
类和命名
类有什么区别。
在我的应用程序中,我使用 Registry
类。但我想知道命名
类及其用途?
In my application I am using Registry
class. But I want to know about Naming
class and its uses ?
推荐答案
区别在于命名
是一个带有静态方法的实用程序类,而 Registry
是一个远程接口。不出所料,命名
在内部调用注册表
。请注意,传递给 java.rmi.Naming
的名称
参数是URL格式,并包含注册表,而 java.rmi.registry.Registry
,名称
只是名称。
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.
这篇关于类java.rmi.registry.Registry和java.rmi.Naming之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!