手动检查LocateRegistry是否可以存在? [英] Is it possible to manually check LocateRegistry existing?
问题描述
我已找到获得的安全方式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屋!