Search code examples
javasynchronizationrmi

Does local method call wait for remote return value in java RMI?


I have a question about how local and remote methods cooperate in Java RMI. Here's the ideal situation:

localClass.setValue(server.getValue());

Does localClass.setValue(..) awaits for the return value from the server or do I have to make sure of it using some sort of synchronization in local? What happens if the server needs like 5 seconds to execute getValue()?


Solution

  • Not quite.

    Arguments are evaluated left to right before the method is called.

    So localClass.setValue() isn't even called until the parameter value returned by server.getValue() is available. So the client waits as long as that takes, and then calls localClass.setValue(). It isn't setValue() that does the waiting, it is the stub's call to server.getValue().

    You don't have to do anything about it yourself.