我什么时候应该调用 Naming.unbind()?
我有一些代码可以通过 RMI 提供。
如果我的程序异常终止,我将不会调用 Naming.unbind(),并且对该对象的引用可能会挂在 RMI 注册表中,并且随后对同名的 Naming.bind() 的调用将会失败。
如何确保清除恶意引用?
I have some code which I am making available via RMI.
If my program terminates abnormally, I won't have called Naming.unbind(), and a reference to the object will presumably be hanging around in the RMI registry, and subsequent calls to Naming.bind() with the same name will fail.
How do I make sure that rogue references are cleared up?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有一种叫做分布式垃圾收集器(DGC)的东西。 它使用租约来跟踪陈旧的绑定,并在不使用时收集它们。 设置导出的 leaseValue 系统属性JVM 确定绑定何时到期。
该值设置得太低会导致网络流量增加。 将其设置得太高会导致陈旧引用保留太长时间。 您可以在客户端查找后调用幂等方法,以确保对象处于活动状态(或使用 Weblogic 智能存根之类的东西)。 在服务器端,您可以检查注册表,如果存在绑定,则取消注册它(如果它已经过时),处置远程对象并导出一个新对象,或者只是保留它(如果它是活动的)。
There is something called Distributed Garbage Collector (DGC). It uses leases to track stale bindings and will collect them once they are not used. Set the leaseValue system property of the exporting JVM to determine when a binding expires.
Setting the value to too low would result in increased network traffic. Setting it too high will result in stale references being held too long. You can call an idempotent method after lookup on the client side just to make sure the object is live (or use something like the Weblogic smart stubs). On the server side, you can check the registry and if a binding exist either unregister it (in case it's stale), dispose the remote object and export a new one or just leave it (if it's live).