我有以下RMI服务器代码:
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();
}
}
Run Code Online (Sandbox Code Playgroud)
当上述程序运行时,它会一直运行以等待客户端请求.但我不明白的是while(true){};,除了停止整个程序之外,该程序是什么让它继续运行而不是类似的以及如何阻止它的监听?
它继续运行的是由RMI启动的非守护进程监听线程.要使其退出,请使用UnicastRemoteObject.unexportObject()取消绑定名称并取消导出注册表和远程对象.
| 归档时间: |
|
| 查看次数: |
2792 次 |
| 最近记录: |