如何关闭在特定端口上运行的rmiregistry?

slo*_*kar 8 java linux rmi rmiregistry

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

Gra*_*ray 10

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

// 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);
}
Run Code Online (Sandbox Code Playgroud)

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

我在SimpleJmx JMX客户端/服务包中使用此代码.


slo*_*kar 8

经过这么多的麻烦,我突然意识到rmiregistry在shell的背景下运行.因此,我们必须先将它关闭,然后将其关闭,然后将其关闭.它奏效了.

BTW将它带到前台只需键入:

% fg
Run Code Online (Sandbox Code Playgroud)

然后关闭它类型:

Ctrl + c

而已.非常感谢所有试图帮助我的人.