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.
Terminate Java RMI server application
You should add a self writtem RMIService interface available in your RMIServer so that a program that wishes to stop the running server instructs it to stop.
Your app that tries to stop the server just unbinds some object, as it is not the running rmi server process itself it will not have a big effect.
if your rmi sever is process a, you should write an app (using rmi) running as process b to send a message to process a to stop it.
Remote method invocation port in use
The rmiregistry
is using port 1099 in its process so you can't use it in yours. Either:
- Start the registry in the same process, via
LocateRegistry.createRegistry()
(preferred). - Export your object on a different port.
- Start the
rmiregistry
on a different port other than 1099.
Java RMI and netstat output
tcp6 0 0 10.1.1.1:1099 10.1.1.2:33400 ESTABLISHED
A connection between a client on port 33400 and a server on port 1099. You can't tell that from this line alone but you mentioned RMI which uses 1099, and there would have been a prior line with 1099 LISTENING.
tcp6 0 0 10.1.1.1:1099 10.1.1.1:33378 ESTABLISHED
A connection between a client on port 33378 and a server on port 1099. Same remark as above.
tcp6 0 0 10.1.1.1:33408 10.1.1.1:1099 ESTABLISHED
A connection between a client on port 33408 and a server on port 1099. Same remark as above. If the client was on a different host, this line would only show at the client host.
tcp6 0 0 10.1.1.1:1099 10.1.1.1:33408 ESTABLISHED
The other side of that connection. This line only shows at the server host.
tcp6 0 0 10.1.1.1:46866 10.1.1.2:1099 ESTABLISHED
tcp6 0 0 10.1.1.1:1099 10.1.1.2:33404 ESTABLISHED
tcp6 0 0 10.1.1.1:33378 10.1.1.1:1099 ESTABLISHED
tcp6 0 0 10.1.1.1:46862 10.1.1.2:1099 ESTABLISHED
tcp6 0 0 10.1.1.1:46864 10.1.1.2:1099 ESTABLISHED
tcp6 0 0 10.1.1.1:1099 10.1.1.2:33402 ESTABLISHED
tcp6 0 0 10.1.1.1:46860 10.1.1.2:1099 ESTABLISHED
Et cetera.
Is this expected?
Yes.
Why am I seeing port #'s like 33400, 33378 etc?
Because connections have two ends: a server end and a client end, and the client port is normally chosen fairly randomly.
Or is my understanding of how source and destination ports work wrong? I was hoping to see all connections (registry lookup and remote service calls) going to port 1099 only.
They are. But there are client ends to those connections.
This is really a question about TCP and netstat
, not RMI or Java.
Related Topics
Listview Is Blank While Using Getfilter Function
Why I Cant Use the Populateviewholder Override Method
Trying to Locate a Leak! What Does Anon Mean for Pmap
Compute Hex Color Code for an Arbitrary String
Convert Existing Eclipse Project to Maven Project
How to Decompile a Whole Jar File
How to Interrupt a Serversocket Accept() Method
Java 8 Nested (Multi Level) Group By
Is It Expensive to Use Try-Catch Blocks Even If an Exception Is Never Thrown
Android: How to Stretch an Image to the Screen Width While Maintaining Aspect Ratio
JSONparser from Androidhive Tutorial, Nosuchmethoderror in Defaulthttpclient
What Happens When I Throw a C++ Exception from a Native Java Method
Jsp, Can It Work Similar to Yield, Layout, Content_For in Ruby/Rails/Erb
Access Restriction: the Type 'Application' Is Not API (Restriction on Required Library Rt.Jar)
Sockets: Discover Port Availability Using Java