Reputation: 214
I am new to java rmi. And I want to create a rmi program as a service. For example, I got a remote interface:
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
}
}
And I also have a class to register it:
class Server {
public Server () {
Registry svcReg = LocateRegistry.createRegistry(999);
Handler handler = new HandlerImpl (1000);
svcReg.rebind("insert", handler);
}
}
Now if a write the program with
Server server = new Server();
When the program terminates, the service is gone. What is proper way to make Server like a service that it runs in the background and the "remote method" can still be called?
Thanks!
Upvotes: 0
Views: 154