How can I programmatically stop a RMI server?

Edward Harned

RMI Servers start a thread that never ends. This is so that the Server is persistent until manually shut down.

However, you can provide a remote method, shutDown(), for the Remote Server.

This method starts a shutdown thread. The shutdown thread remains waiting for a notify().

When the Server finishes all clean-up processing it wakes up the shutdown thread.

The shutdown thread, after a two (2) second delay, calls System.exit(0) to end the Java Virtual Machine. The delay is so that messages from the Server to the initiating Client complete the journey.