如何关闭在特定端口上运行的rmiregistry? [英] How to close rmiregistry running on particular port?

查看:2023
本文介绍了如何关闭在特定端口上运行的rmiregistry?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究Java RMI。我在端口2028上运行我的rmiregistry没有什么问题,因为我已经使用那个来运行我的测试程序。我可以使用其他端口运行我的程序,但我想知道,我们如何关闭在特定端口上运行的rmiregistry?

I am working on Java RMI. I am having little issue with running my rmiregistry on port 2028 as I allready used that one to run my test program. I can run my program using other port but I would like to know, How we can close rmiregistry running on perticular port ?

推荐答案

如果你想在编程中这样做,我们会这样做:

If you want to do this in programming, we do something like:

// create the registry
Registry rmiRegistry = LocateRegistry.createRegistry(port);
...
// connect to it
JMXConnectorServer connector =
    JMXConnectorServerFactory.newJMXConnectorServer(url,
        new HashMap<String, Object>(),
        ManagementFactory.getPlatformMBeanServer());
// do stuff with it ...

// close the connection
if (connector != null) {
    connector.stop();
}
// deregister the registry
if (rmiRegistry != null) {
    UnicastRemoteObject.unexportObject(rmiRegistry, true);
}

这是我们的JMXServer类的完整代码。我们在创建其中2个并完全取消注册时遇到问题,因此我们确保在不同的端口上运行我们的单元测试。

Here's the full code for our JMXServer class. We have problems creating 2 of these and completely unregistering them so we make sure to run our unit tests on different ports.

我在 SimpleJmx JMX客户端/服务包。

I use this code in my SimpleJmx JMX client/service package.

这篇关于如何关闭在特定端口上运行的rmiregistry?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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