我正在从事Java RMI的工作。我在端口2028上运行我的rmiregistry时遇到了一点问题,因为我已经使用这个端口运行了我的测试程序。我可以使用其他端口运行我的程序,但我想知道,如何关闭在特定端口上运行的rmiregistry?
发布于 2011-12-05 21:28:42
如果你想在编程中做到这一点,我们可以这样做:
// 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。我们在创建其中的两个并完全注销它们时遇到了问题,所以我们要确保在不同的端口上运行单元测试。
我在我的SimpleJmx JMX /service包中使用了这段代码。
发布于 2011-12-05 21:47:49
如果您正在从shell运行rmiregistry,请尝试使用以下命令关闭它:
Process p =
Runtime.getRuntime().exec("ps -ef | grep rmiregistry | awk '{ print $2 }' | kill -9");我对shell命令不是很熟悉,但我希望您能理解。
发布于 2014-04-10 21:14:04
如果rmi注册表已经在使用该端口,并且您希望在不使用其他端口的情况下重新绑定服务。你可以试试下面的代码
Registry registry = null;
try {
registry = LocateRegistry.createRegistry(1099);
} catch (ExportException ex) {
registry = LocateRegistry.getRegistry(1099);
} catch (RemoteException ex) {
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
}https://stackoverflow.com/questions/8386001
复制相似问题