Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what make rmi server keep running?

Tags:

java

rmi

I have the following RMI server code:

public class ServerProgram {
    public ServerProgram() {
        try {
            LocateRegistry.createRegistry(1097);
            Calculator c = new CalculatorImpl();
            String name = "rmi://host:port/name";
            Naming.rebind(name, c);
            System.out.println("Service is bound......");
        } catch (Exception e) {
        }
    }
    public static void main(String[] args) {
        new ServerProgram();
    }
}

When the above program running, it keeps running to wait for client requests. But what I do not understand is what make that program keeps running while it is not in something like while(true){}; and how to stop it from listening, except stopping the whole program?

like image 246
ipkiss Avatar asked Sep 16 '11 14:09

ipkiss


People also ask

How do I stop RMI?

Softly typing keys prevents you from placing so much pressure on your hands and fingers which can, in turn, hurt your wrist and arm. Don't bend your wrists when typing. Keep your feet flat on the floor to improve posture. Sit up in your seat and make sure your chair supports your spine.

Are RMI server is responsible for?

RMI stands for Remote Method Invocation. It is a mechanism that allows an object residing in one system (JVM) to access/invoke an object running on another JVM. RMI is used to build distributed applications; it provides remote communication between Java programs. It is provided in the package java.

What is RMI and how it works?

RMI treats a remote object differently from a non-remote object when the object is passed from one Java virtual machine to another Java virtual machine. Rather than making a copy of the implementation object in the receiving Java virtual machine, RMI passes a remote stub for a remote object.


2 Answers

What makes it keep running is a non-daemon listening thread started by RMI. To make it exit, unbind the name and unexport both the Registry and the remote object, with UnicastRemoteObject.unexportObject().

like image 159
user207421 Avatar answered Nov 08 '22 07:11

user207421


To stop it, you should call

LocateRegistry.getRegistry().unbind("rmi://host:port/name");
like image 42
datalost Avatar answered Nov 08 '22 09:11

datalost