是什么让 rmi 服务器继续运行? [英] what make rmi server keep running?

查看:43
本文介绍了是什么让 rmi 服务器继续运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆