How to close rmiregistry running on particular 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);
}
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.
I use this code in my SimpleJmx JMX client/service package.
After so much of hassle I suddenly realize that rmiregistry runs in background of shell. So all we have to do close it first bring it to foreground and then close it. And it worked.
BTW to bring it to foreground just type:
% fg
and then to close it type:
Ctrl + c
That's it. Thanks a lot everyone who tried to help me out.