1

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?

Sam YC
  • 10,725
  • 19
  • 102
  • 158
  • Your [UnicastRemoteObject](http://docs.oracle.com/javase/8/docs/api/java/rmi/server/UnicastRemoteObject.html) can be created with a explicit port if you want. Otherwise it will choose one randomly for you. Aside from the port, you will also expose the RMI [Registry](http://docs.oracle.com/javase/8/docs/api/java/rmi/registry/Registry.html) port which by default is 1099. – Edwin Dalorzo May 02 '15 at 13:36
  • @EdwinDalorzo can all my `RemoteObject` created on same port? So I don't need so many port for each `RemoteOjbect`? – Sam YC May 02 '15 at 13:59
  • Hmm, I am not exactly an expert on RMI, but I reckon every UnicastRemote object would open a socket, so I doubt that you can reuse the same port for different objects. But I suppose you can try and prove my theory. – Edwin Dalorzo May 02 '15 at 14:06

1 Answers1

2

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.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • 1
    There should be a mechanism for [rmi] tag based question on Stack Overflow here : - Answers given by author named `EJP` is bound to be 100% correct,must be automatically upvoted twice as I've seen many of your answers not even receiving scores,though,they are clearly correct & the best. I'm a true fan of yours... – Am_I_Helpful May 02 '15 at 15:02