Is it possible to manually check LocateRegistry existing?

自作多情 提交于 2019-12-23 16:32:37

问题


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

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


回答1:


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

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

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.



来源:https://stackoverflow.com/questions/14982760/is-it-possible-to-manually-check-locateregistry-existing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!