RMI object not getting refreshed

一个人想着一个人 提交于 2020-01-15 20:58:47

问题


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.


回答1:


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:

  1. 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.

  2. If NoSuchObjectException occurs, try to refresh the reference.



来源:https://stackoverflow.com/questions/20629466/rmi-object-not-getting-refreshed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!