开发者

java RMI: how to detect whether the server has crashed?

开发者 https://www.devze.com 2023-02-25 14:05 出处:网络
I have a 3rd-party Java library I\'m trying to encapsulate in a separate JVM with RMI (because the library has native calls that crash the JVM, and there are applications for running the RMI server on

I have a 3rd-party Java library I'm trying to encapsulate in a separate JVM with RMI (because the library has native calls that crash the JVM, and there are applications for running the RMI server on another machine).

My Java app on the client side works like this, at least when everything runs on the same machine:

  1. find the object bound to FooBar/<id> in the RMI registry
  2. if it's already bound to the registry, use it and goto step 5.
  3. otherwise, start up a separate JVM to create the object in question.
  4. wait for a short timeout
  5. find the object bound to FooBar/<id> in the RMI registry
  6. if we 开发者_StackOverflow中文版have an object, success! (otherwise failure)

The problem I have, is when the other JVM crashes, it seems to leave the binding present in the RMI registry, and then I end up using a phantom object connected to nothing.

Is there a way I can somehow check the proxy object bound to the RMI registry in step 2, so if the object is invalid, I can create a new one to rebind() to the RMI registry?


set a timeout on your rmi requests (see here). then if a request times out, consider the object dead. additionally, when i want very reliable rmi code, i will wrap the rmi calls on the client side with some sort of retry/backoff functionality (assuming your outgoing calls are idempotent). thus, you would try connecting a few times with delays in between before considering the target object dead.

(and no, there is no way to determine if the remote object is dead without trying to contact it).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号