Search code examples
javarmirmiregistry

Where is the Java RMI server listening on?


I am reading through few tutorial (one of them here) related to Java RMI, I found myself hardly understand about the RMI server.

I start a Java Main program, and create a UnicastRemoteObject, after that bind the object in the RMI registry server (follow the tutorial). After that the Java Main program exit after the binding.

The parent class of UnicastRemoteObject is RemoteServer, I assume every remote object (which is also UnicastRemoteObject) that I created is a Java process (JVM) that listening on one anonymous port.

So if I have 10 remote object, then I have 10 ports occupied to serve the client remote invocation? This doesn't sound right, but I can't really find where is the RMI server that actually established and how many port it will occupy for the remote client invocation?

Can anyone explain in detail how this thing work?


Solution

  • I start a Java Main program, and create a UnicastRemoteObject, after that bind the object in the RMI registry server (follow the tutorial). After that the Java Main program exit after the binding.

    No it won't. It will stay active as long as the remote object remains exported.

    The parent class of UnicastRemoteObject is RemoteServer, I assume every remote object (which is also UnicastRemoteObject) that I created is a Java process (JVM) that listening on one anonymous port.

    No. It is one Java object that exists inside the current JVM. Not a separate process.

    So if I have 10 remote object, then I have 10 ports occupied to serve the client remote invocation?

    No. Unless you specify a port, you'll get a system-allocated port. Normally the port will be shared among all the remote objects you export from this JVM.

    This doesn't sound right

    It isn't.

    but I can't really find where is the RMI server that actually established and how many port it will occupy for the remote client invocation?

    It is deep inside the RMI implementation classes.