0
我正在阅读关于网络和java从this书。RMI Java应用程序不按预期工作
问题是我正在尝试做本书中列出的一个示例,它位于第153页至第159页(段落5.4使用RMI有意义的)。
我做了一些改变,主要是他使用旧的Vector我用ArrayList替换它。同样在客户端,我做了一些这样的小改动:
public static void main(String[] args) {
try {
// Obtain a reference to the object from the
// registry and typecast it into the appropriate
// type...
String name = "//localhost/Service1";
Stp temp = (Stp) Naming.lookup(name);
ArrayList<Account> acc = temp.getAccs();
System.out.println(acc);
for (Account cnt : acc) {
if ("george".equals(cnt.name)) {
cnt.get(10);
System.out.println(cnt);
}
}
} catch (ConnectException conEx) {
System.out.println("Unable to connect to server!");
System.exit(1);
} catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
}
}
它工作得很好,或者几乎没有问题。当从客户端调用get(int number)方法(它应该减少平衡)时,它实际上做它意味着做什么。问题是,如果我从另一个cmd窗口打开另一个客户端,或者即使再次运行同一客户端,也不会进一步降低余额值。如果余额是100,客户端运行get(10)
,他将看到90.但是,如果客户端代码再次运行另一个get(10)
,则余额不会更新并保持为90.应该是80.
谢谢任何有关此信息!
感谢您的快速回答,您能给我一个例子,或者至少说明一下吗?我有点困惑。干杯。 –
您需要向您的Stp界面添加一个远程方法,用于更改帐户列表中第n个元素的值。事实上,你是否应该返回账户列表是值得怀疑的。您应该返回个人帐户,并且可能帐户本身应该是远程接口。 – EJP
谢谢。有效!很愚蠢的是我之前做过的事情,现在才意识到它。干杯。 –