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?
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.
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.
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.
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().
To stop it, you should call
LocateRegistry.getRegistry().unbind("rmi://host:port/name");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With