Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am working on Java RMI. I am having little issue with running my rmiregistry on port 2028 as I already 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 particular port ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
89 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...