当我运行一个使用Java的客户端服务器应用程序时,我注意到,即使我没有在命令提示符中启动"rmiregistry“,它似乎仍然有效。我注意到节目中的不同之处:
try {
LocateRegistry.getRegistry(1099).list();
System.out.println("rmiregistry WAS started before running the application"); }
catch (RemoteException e) {
LocateRegistry.createRegistry(1099);
System.out.println("rmiregistry WAS NOT started before running the application"); }任何有这种知识的人都能分辨出正在发生的事情以及它是如何影响程序的?
发布于 2013-12-02 23:11:08
LocateRegistry.getRegistry(1099).list();
System.out.println("rmiregistry WAS started before running the application"); }这个信息是误导的。getRegistry()不执行任何网络通信,因此它成功的事实并不是注册表正在运行的有效指示。只有使用getRegistry()的结果才能告诉您这一点。
你要把这个背到前面去。您必须先尝试createRegistry()调用,如果失败,getRegistry() call.createRegistry()‘将在注册表已经运行时失败,如果没有运行,则会成功。
https://stackoverflow.com/questions/20337014
复制相似问题