Reputation: 333
I am using RMI in my project, we have a RMI Server and RMI Client. Client is in webapplication, so we are storing server reference in common constants.
I want to know, how expensive is it to do lookup for server in registry everytime we need server instance. or is it better to do look up once and store it in some constant.
If i store it in constant then problem begins if RMI server is restarted. because that constant variable holds old reference and it throws java.rmi.NoSuchObjectException: no such object in table
Any Inputs are welcome.
Upvotes: 1
Views: 308
Reputation: 565
If you want your client application to withstand all server restarts, you should anyway protect it from communication failures, including java.rmi.NoSuchObjectException. Note that it is possible, although not very likely, that a server restart occurs between the lookup and the request execution. In that case, even if you did a lookup before every request, you wouldn't be safe. So the recommendation is as follows:
Do a lookup once and keep the reference. An additional benefit of this would be that your application will be able to discover misconfiguration or other problems on initialization.
If NoSuchObjectException occurs, try to refresh the reference.
Upvotes: 1