Reputation: 9347
I am trying to understand Oracle's RMI Tutorial for java and I had some questions. For reference the tutorial is linked here:
1) In the server example, the last line of the main function is: System.out.println("ComputeEngine bound");
. Normal execution would say that at this point, the main function exits and the program terminates. However, something is causing the program to block. Does anyone know why the program blocks (rather than exiting after printing compute engine bound) when you run the server?
2) In relation to the previous question, it would seem the server is blocking and listening on a port. What port is it listening on? How does the RMIRegistry know what port the server is listening on?
3) My other question is when the client gets the stub from the RMIRegistry (using registry.lookup
) and then calls executeTask
on this stub, does the computation happen on the machine running the RMIRegistry, or the machine running the server code? i.e. does the stub tell the RMIRegistry to run executeTask
on a computeEngine
instance living in the registry or within the server's main
function?
Upvotes: 0
Views: 679
Reputation: 310840
Upvotes: 0
Reputation: 23301
RMI creates background listening threads. The program will not terminate until those threads die.
It specifies 0 as the port, which means it uses a random port which the OS defines the range for.
The stub encapsulates a TCP/IP call to notify the server to call that method. So that actual implementation runs on the server hosting the code. If you put a println on the server code you will see it print out when that function is called.
Upvotes: 2