gpt4 book ai didi

java - 是否可以手动检查 LocateRegistry 是否存在?

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:30:23 25 4
gpt4 key购买 nike

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

最佳答案

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

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

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

这不是一个有效的问题。这是一个几乎免费的电话。没有网络 Activity 。

关于java - 是否可以手动检查 LocateRegistry 是否存在?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14982760/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com