Can my remote object obtain notification when there are no live references to it?
Created May 4, 2012
Govind Seshadri Yes, you can enable remote objects to get notified as soon as there are no valid references to it.
Although the distributed garbage collection mechanism takes care of memory management
issues, explicit notification can help the remote server release valuable resources like
network and database connections immediately.
Any remote object that implements java.rmi.server.Unreferenced interface can get immediate notification via the unreferenced() method as soon as the server does not have any valid references to it. The following code snippet demonstrates how:
public class RemoteServerImpl extends UnicastRemoteObject implements MyRemoteInterface, Unreferenced { public RemoteServerImpl() { super(); . . . //allocate resources } . . . public void unreferenced() { //deallocate resources here } }