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?