RMI远程对HashMap的读写
一.测试用的接口
public interface TestHashMap extends Remote{
public void put(HashMap map,String key,String value) throws RemoteException;
public Object get(HashMap map,String key) throws RemoteException;
}
二.接口实现类
public class HashMapImpl extends UnicastRemoteObject implements TestHashMap {
public HashMapImpl() throws RemoteException {
super();
}
public void put(HashMap mapname, String key, String value) throws RemoteException {
mapname.put(key, value);
}
public Object get(HashMap mapname, String key) throws RemoteException {
return mapname.get(key);
}
}
三.注册服务那就没贴了.因为那些都是不变的
四.客户端
public class RmiClient {
public static HashMap map=new HashMap();
public static void main(String[] args){
TestHashMap thm = RmiInstance.testHash; //(RmiInstance.testHash)这个是自己写的一个初始化块
thm.put(RmiClient.map, "cood", "dooc");
System.out.println(thm.get(RmiClient.map, "cood"));
}
}
五.打印结果
null
我给RmiClient.map中put了一个K,V.但是我再次获取的时候却获取不到这个值