简体   繁体   中英

Java RMI programming a service

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!

您可以使用Apache Commons Daemon来完成。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM