是什么让 rmi 服务器继续运行? [英] what make rmi server keep running?
问题描述
我有以下 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();
}
}
当上述程序运行时,它会一直运行以等待客户端请求.但我不明白的是,是什么让该程序在不在 while(true){};
之类的情况下继续运行,以及如何阻止它监听,除了停止整个程序?>
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?
推荐答案
让它一直运行的是一个由 RMI 启动的非守护进程监听线程.要使其退出,请使用 UnicastRemoteObject.unexportObject() 取消绑定名称并取消导出注册表和远程对象.
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().
这篇关于是什么让 rmi 服务器继续运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!