我正在研究 Java RMI。我在端口 2028 上运行我的 rmiregistry 没有什么问题,因为我已经使用它来运行我的测试程序。我可以使用其他端口运行我的程序,但我想知道,我们如何关闭在特定端口上运行的 rmiregistry?
最佳答案
如果你想在编程中这样做,我们会做类似的事情:
// 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);
}
这是 full code for our JMXServer class .我们在创建其中 2 个并完全注销它们时遇到问题,因此我们确保在不同的端口上运行我们的单元测试。
我在我的 SimpleJmx 中使用此代码JMX 客户端/服务包。
关于java - 如何关闭在特定端口上运行的 rmiregistry?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8386001/