Garbage Collection

The following is a typical garbage collection-related error:

java.rmi.ConnectException: connection refused or timed out to BasicObjectEndpoint[afeb7958-8cff-41cb-8042-ec884a52e9a6,TcpEndpoint[192.168.2.1:3558]]; nested exception is:
        java.net.ConnectException: Connection refused

If the service has been garbage collected, then there will be no server listening for connections to it, so any connection request will be refused. This error is more likely to happen with Jini 2.0, where objects may be garbage collected if there are no active references.

The solution is to ensure that an active reference is kept to the service. The main() method should contain a reference to the server (not just create it, but also keep a variable pointing to it). The server should also keep a reference to the service implementation. An alternative is to keep a static reference to the service implementation. Similarly, if you are using a JoinManager to keep services leased, then there should be an active reference to it or it may be garbage collected and cause any leases to expire.