java.rmi.registry,类java.rmi.registry.Registry和java.rmi.Naming之间的区别

Registry类和Naming类在Java RMI中扮演不同角色。Naming是一个包含静态方法的工具类,提供方便的绑定和查找操作,而Registry是一个远程接口,用于直接交互。Naming内部调用Registry进行操作。使用Naming的rebind方法可以一步完成查找和绑定,而Registry则需要先获取Registry对象再执行绑定。
摘要由CSDN通过智能技术生成

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 ?

解决方案

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值