【问题标题】:Is it possible to manually check LocateRegistry existing?是否可以手动检查 LocateRegistry 是否存在?
【发布时间】:2013-02-20 14:51:40
【问题描述】:

have found 是获取LocateRegistry 的安全方法(即使注册表尚不存在)。

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);
}

是否可以先检查注册表是否存在,根据检查结果使用getRegistrycreateRegistry

【问题讨论】:

  • 没有。如果函数中有错误,您需要捕获它并做出相应的反应。
  • @mercutio 我不会尝试完全避免异常。但我想避免在不存在时不必要地调用getRegistry。我已经更新了问题。

标签: java exception rmi


【解决方案1】:

是否可以先检查registry是否存在,根据检查结果使用getRegistry或createRegistry?

当然。先试试createRegistry();抓住ExportException,这意味着它已经在运行,并无条件地执行getRegistry()

我希望避免在 getRegistry 不存在时对其进行不必要的调用

这不是一个有效的担忧。这是一个几乎免费的电话。没有网络活动。

【讨论】:

    猜你喜欢
    • 2018-07-28
    • 2017-02-16
    • 1970-01-01
    • 2011-01-08
    • 1970-01-01
    • 2022-01-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多