我是java rmi的新手。我想创建一个rmi程序作为服务。例如,我有一个远程接口:
public interface Handler implements Remote {
public void insert (String str) throws RemoteException, NotBoundException;
}
public class HandlerImpl extends UnicastRemoteObject implements Handler {
public HandlerImpl (int port) {
super(port);
}
public void insert (String str) throws RemoteException, NotBoundException {
// insert string to a file
}
}
我还有一个课程来注册它:
class Server {
public Server () {
Registry svcReg = LocateRegistry.createRegistry(999);
Handler handler = new HandlerImpl (1000);
svcReg.rebind("insert", handler);
}
}
现在如果用
编写程序Server server = new Server();
当程序终止时,服务就消失了。什么是使服务器像在后台运行的服务和“远程方法”仍然可以被调用的正确方法?
谢谢!