Search code examples
rmiunbindsystem.exit

Unbind at System.exit(0)


I'm working with Java RMI. The problem is that, by closing a thread, or call System.exit(0), I need the object registered with the RMI registry to execute an unbind() to remove all associations with the object. When we perform System.exit(0), the object is already registered with the RMI registry.

How I can do so by calling System.exit(0) the unbind() is made of the object in particular? I had thought about making a System.exit() override , but apparently that's not the solution.


Solution

  • The problem is that, by closing a thread, or call System.exit(0), I need the object registered with the RMI registry to execute an unbind() to remove all associations with the object.

    So do that. But there is no such thing as 'closing a thread', and even exiting a thread doesn't require you to unbind anything.

    When we perform System.exit(0), the object is already registered with the RMI registry.

    Good, so the unbind() will succeed. Not sure what point is being made her. Did you mean 'still registered'?

    How I can do so by calling System.exit(0) the unbind() is made of the object in particular?

    You can't. You have to precede the System.exit() call with an unbind() call.

    I had thought about making a System.exit() override , but apparently that's not the solution.

    You can't override static methods, and System is final.

    It seems you may have System.exit() spattered all over the place, which is already poor practice.

    The simple answer is not to call System.exit() at all, but to unbind and unexport the object instead. Then the RMI threads will exit and your JVM will exit of its own accord, as long as you don't have any non-daemon threads of your own.