Re: Correct way of avoiding a shutdown delay caused by the Reaper thread

Vinod Johnson - Sun Microsystems <[email protected]> Tue, 8 Aug 2006 13:53:10 -0400
Newsgroups gmane.comp.java.sun.rmi
Message-ID <[email protected]>
Greg Luck wrote:

> Vinod
>
> The code fragment in question is as follows. It is from
> RMICacheManagerPeerListener in ehcache.
> When we shutdown the cache manager, we need to shutdown the RMI
> listener. We call dispose,
> Dispose iterates through the bound and exported objects and unbinds
> and unexports them.
>
> The issue which as come about in production is that when people are
> shutting down Tomcat, it is taking
> up to a few minutes for this to happen. The Reaper thread was the cause.
>
> The people having the trouble believe they have found the fundamental
> cause, which they believe is that
> UnicastRemoteObject.unexportObject(rmiCachePeer, false); was being
> called before Naming.unbind(rmiCachePeer.getUrl());
>

Unfortunately this does not make sense to me. The order in which you
performed this operation should not have made a difference with regards
to Reaper thread termination. Successful unexporting of all exported
remote objects should result in the Reaper thread exiting promptly.

The only thing I could think of is that there are other exported objects
which have not been unexported, but have become candidates for GC. In
this case, the Reaper thread would not terminate until a local GC occured.

> We have changed the ordering so that unbind happens before unexport
> which seems to have resolved their problem.
>
> I have also added a Runtime.getRuntime().gc(); at the end of dispose.
> I have seen people work around this problem by doing
> that.
>
In your situation, this would not be necessary. To reiterate what I said
earlier, successful unexporting should do the trick.

--
- vinod

===========================================================================
To unsubscribe, send email to [email protected] and include in the body
of the message "signoff RMI-USERS".  For general help, send email to
[email protected] and include in the body of the message "help".

For a list of frequently asked RMI questions please refer to:
http://java.sun.com/j2se/1.3/docs/guide/rmi/faq.html

To view past RMI-USERS postings, please see:
http://archives.java.sun.com/archives/rmi-users.html