Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

rmi

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 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?

like image 770
Jason S Avatar asked Nov 27 '25 09:11

Jason S


1 Answers

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

like image 182
jtahlborn Avatar answered Nov 28 '25 23:11

jtahlborn