手动检查LocateRegistry是否可以存在? [英] Is it possible to manually check LocateRegistry existing?

查看:154
本文介绍了手动检查LocateRegistry是否可以存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已找到获得的安全方式LocateRegistry (即使注册表不存在)。

I have found a safe way to get LocateRegistry (even if the registry does not already exist).

Registry registry = null;
try {
    registry = LocateRegistry.getRegistry(52365);
    registry.list();
    // This call will throw an exception if the registry does not already exist
}
catch (RemoteException e) { 
    registry = LocateRegistry.createRegistry(52365);
}

有可能首先检查注册表的存在并使用根据检查结果,getRegistry createRegistry

Is it possible to firstly check registry existence and use getRegistry or createRegistry in accordance with the result of the check?

推荐答案


是否可以首先检查注册表的存在并根据检查结果使用getRegistry或createRegistry?

Is it possible to firstly check registry existence and use getRegistry or createRegistry in accordance with the result of the check?

当然可以。首先试试 createRegistry()捕获 ExportException ,这意味着它已经在运行,并无条件地执行 getRegistry()

Certainly. Just try the createRegistry() first; catch the ExportException, which means it's already running, and do the getRegistry() unconditionally.


我想避免不必要的调用getRegistry不存在

I want avoid unnecessary calling of getRegistry when it doesn't exist

这不是一个有效的问题。这是一个几乎没有成本的电话。没有网络活动。

That's not a valid concern. It is a virtually cost-free call. No network activity.

这篇关于手动检查LocateRegistry是否可以存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆