city2app.java
来自「《JAVA分布式程序设计》一书的源代码。」· Java 代码 · 共 45 行
JAVA
45 行
import java.rmi.*;/** * @(#)City2App.java * @author Qusay H. Mahmoud */public class City2App { public static void main(String argv[]) { Remote obj = null; CityFactoryImpl cityFactory; City2 ottawa = null; City2 toronto = null; int ottawaPopulation = 0; int torontoPopulation = 0; try { obj = Naming.lookup("//hostname/CityFactory"); } catch (Exception e) { e.printStackTrace(); } if (obj instanceof CityFactoryImpl) { cityFactory = (CityFactoryImpl) obj; } // create a server for each city try { ottawa = new CityFactoryImpl().getCityServer("Ottawa"); toronto = new CityFactoryImpl().getCityServer("Toronto"); } catch (RemoteException e) { e.printStackTrace(); } // invoke methods on those servers try { ottawaPopulation = ottawa.getPopulation(); torontoPopulation = toronto.getPopulation(); } catch (RemoteException e) { e.printStackTrace(); } // print the results System.out.println("The population of Ottawa is: "+ottawaPopulation); System.out.println("The population of Toronto is: "+torontoPopulation); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?