I am writing an RMI server (with java.rmi packages) for the first time. Can anyone give advice on how to capture the RMI server termination so that I can perform some logic before it is terminated?

For info: my RMI server implementation extends UnicastRemoteObject, has the public static void main method to instantiate the server object and bind it to RMI registry (usual stuff)