通过引用传递未在 RMI 中为 ArrayList 返回 [英] Pass by reference not returning in RMI for ArrayList
问题描述
我有一个 RMI 调用定义为:
I've got an RMI call defined as:
public void remoteGetCustomerNameNumbers(ArrayList<String> customerNumberList, ArrayList<String> customerNameList) throws java.rmi.RemoteException;
该函数执行数据库查找并填充两个 ArrayList.调用函数什么也得不到.我相信这适用于 Vector 类型.
The function does a database lookup and populates the two ArrayLists. The calling function gets nothing. I believe this works with Vector types.
我是否需要使用 Vector,或者有没有办法让它在不进行两次调用的情况下工作.我还有一些我可能会用到的其他想法,比如返回一个键/值对,但我想知道我是否可以让它发挥作用.
Do I need to use the Vector, or is there a way to get this to work without making two calls. I've got some other ideas that I'd probably use, like returning a key/value pair, but I'd like to know if I can get this to work.
更新:
如果可以的话,我会接受到目前为止给出的所有答案.我不知道网络成本,因此重新编写函数以返回 LinkedHashMap 而不是两个 ArrayList 是有意义的.
Update:
I would accept all of the answers given so far if I could. I hadn't known the network cost, so It makes sense to rework the function to return a LinkedHashMap instead of the two ArrayLists.
推荐答案
正如 Tom 所说,您可以传递远程对象.您必须创建一个类来保存实现 Remote 的列表.每当您将实现 Remote 的东西作为参数传递时,只要接收方使用它,它就会转而向调用方进行远程调用返回以使用该对象.
As Tom mentions, you can pass remote objects. You'd have to create a class to hold your list that implements Remote. Anytime you pass something that implements Remote as an argument, whenever the receiving side uses it, it turns around and makes a remote call back to the caller to work with that object.
这篇关于通过引用传递未在 RMI 中为 ArrayList 返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!