RMI 对象未刷新 [英] RMI object not getting refreshed

查看:43
本文介绍了RMI 对象未刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中使用 RMI,我们有一个 RMI 服务器和 RMI 客户端.客户端在 web 应用程序中,因此我们将服务器引用存储在公共常量中.

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.

如果我将它存储在常量中,那么如果 RMI 服务器重新启动,问题就会开始.因为该常量变量持有旧引用并抛出 java.rmi.NoSuchObjectException: no such object in table

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

欢迎任何输入.

推荐答案

如果您希望您的客户端应用程序能够承受所有服务器重启,您无论如何都应该保护它免受通信故障的影响,包括 java.rmi.NoSuchObjectException.请注意,虽然不太可能,但在查找和请求执行之间可能会发生服务器重新启动.在这种情况下,即使您在每个请求之前都进行了查找,您也不安全.所以建议如下:

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. 查找一次并保留参考.这样做的另一个好处是,您的应用程序将能够在初始化时发现配置错误或其他问题.

  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.

如果出现 NoSuchObjectException,尝试刷新引用.

If NoSuchObjectException occurs, try to refresh the reference.

这篇关于RMI 对象未刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆