Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

RMI prevents JVM from exiting

843793Jul 31 2002 — edited Dec 6 2004
I�m having a problem with the JVM (Sun�s 1.3.1_03 linux) not exiting when all of my threads are finished executing. I suspect it has something to do with RMI. At the bottom of this email are all of the threads that have some lifespan in my program. The six threads below, that I�ve singled out, continue to run after the main thread and all my other threads exit. The following RMI threads (preceded by �>�) never go away and appear to keep the JVM alive.

CompileThread0
Signal Dispatcher
RMI TCP Accept-1
RMI Reaper
GC Daemon
JPROBE THREAD (My thread analysis tool)

My programs shutdown method unbinds everything or unexports it if it was exported by UnicastRemoteObject's static exportObject method. (See code snip below). In testing there appears to be no difference from getting the registry (when I run rmiregistry from the command line) or creating the registry within my program, either way the JVM won't exit.

I want my program to exit, without forcing it with System.exit(). Is there any way to shutdown RMI?

*** My RMI shutdown code ***
public void shutDown() {
        fireSystemEvent(new SystemEvent(this, SystemEvent.SHUTDOWN));
        try {
            Registry r = PicapsResourceFactory.getInstance().getRegistry();
            String bindNames[] = r.list();
            for (int i = 0; i < bindNames.length; i++) {
                String bindName = bindNames;
Remote remote = r.lookup(bindName);
try {
if (!UnicastRemoteObject.unexportObject(remote, true)) {
PicapsResourceFactory.getInstance().getLogger(this.getClass()).
error("Failed to unexport " + bindName);
}
} catch (NoSuchObjectException e) {
PicapsResourceFactory.getInstance().getLogger(this.getClass()).
error("No such object " + remote, e);
}
PicapsResourceFactory.getInstance().getLogger(this.getClass()).
debug("Unbinding: " + bindName);
r.unbind(bindName);
}
} catch (RemoteException e) {
PicapsResourceFactory.getInstance().getLogger(this.getClass()).
error("RemoteException throw:", e);
} catch (NotBoundException e) {
PicapsResourceFactory.getInstance().getLogger(this.getClass()).
error("Could not unbind:" + rmiBindName, e);
}
System.gc();
System.runFinalization();
}
In the trace of thread below my only thread that doesn't stop is the following, but it is a daemon thread so it should stop (and does if not using RMI).
(Thread) 'ProcessEventQueues ReferenceQueue Watcher' (id: 15218) started.
*** THREAD TRACE ***
(Init) Application started.
(Recording) Started recording.
(Thread) 'JPROBE THREAD' (id: 9020) started.
(Thread) 'Signal Dispatcher' (id: 9115) started.
(Thread) 'CompileThread0' (id: 9116) started.
(Thread) 'RMI TCP Accept-1' (id: 13693) started.
(Thread) 'RMI Reaper' (id: 13744) started.
(Thread) 'GC Daemon' (id: 13745) started.
(Thread) 'ProcessEventQueues ReferenceQueue Watcher' (id: 15218) started.
(Thread) 'ProcessEventQueue event dispatching thread' (id: 15325) started.
(Thread Wait) 'ProcessEventQueue event dispatching thread' (id: 15325) waiting for notify on com.dartcontainer.mdc.picaps.event.ProcessEventQueueImpl instance 15159 at void com.dartcontainer.mdc.picaps.event.ProcessEventQueueImpl.run():161.
(Thread) 'RMI TCP Connection(2)-127.0.0.1' (id: 17829) started.
(Thread) 'RMI LeaseChecker' (id: 18946) started.
(Thread) 'RMI ConnectionExpiration-[127.0.0.1:2099]' (id: 18998) started.
(Thread Wait) 'ProcessEventQueue event dispatching thread' (id: 15325) received notify on com.dartcontainer.mdc.picaps.event.ProcessEventQueueImpl instance 15159
(Thread Wait) 'ProcessEventQueue event dispatching thread' (id: 15325) waiting for notify on com.dartcontainer.mdc.picaps.event.ProcessEventQueueImpl instance 15159 at void com.dartcontainer.mdc.picaps.event.ProcessEventQueueImpl.run():161.
(Thread) 'main' (id: 5086) stopped.
(Thread) 'Thread-2' (id: 29502) started.
(Thread) 'RMI ConnectionExpiration-[127.0.0.1:2099]' (id: 18998) stopped.
(Thread) 'RMI TCP Connection(2)-127.0.0.1' (id: 17829) stopped.
(Thread) 'RMI TCP Connection(3)-127.0.0.1' (id: 29585) started.
(Thread Wait) 'ProcessEventQueue event dispatching thread' (id: 15325) received notify on com.dartcontainer.mdc.picaps.event.ProcessEventQueueImpl instance 15159
(Thread) 'ProcessEventQueue event dispatching thread' (id: 15325) stopped.
(Thread) 'RMI ConnectionExpiration-[127.0.0.1:2099]' (id: 30059) started.
(Thread) 'RMI RenewClean-[127.0.0.1:41565]' (id: 30415) started.
(Thread) 'RMI TCP Connection(4)-127.0.0.1' (id: 30416) started.
(Thread) 'RMI ConnectionExpiration-[127.0.0.1:41565]' (id: 31377) started.
(Thread) 'RMI TCP Connection(3)-127.0.0.1' (id: 29585) stopped.
(Thread) 'RMI ConnectionExpiration-[127.0.0.1:41565]' (id: 31377) stopped.
(Thread) 'RMI TCP Connection(4)-127.0.0.1' (id: 30416) stopped.
(Thread) 'RMI ConnectionExpiration-[127.0.0.1:2099]' (id: 30059) stopped.
(Thread) 'RMI TCP Connection(5)-127.0.0.1' (id: 31493) started.
(Thread) 'RMI TCP Connection(6)-127.0.0.1' (id: 31727) started.
(Thread) 'RMI RenewClean-[127.0.0.1:41565]' (id: 30415) stopped.
(Thread) 'RMI ConnectionExpiration-[127.0.0.1:41565]' (id: 32286) started.
(Thread) 'RMI TCP Connection(5)-127.0.0.1' (id: 31493) stopped.
(Thread) 'RMI ConnectionExpiration-[127.0.0.1:41565]' (id: 32286) stopped.
(Thread) 'RMI TCP Connection(6)-127.0.0.1' (id: 31727) stopped.
(Thread) 'RMI LeaseChecker' (id: 18946) stopped.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 3 2005
Added on Jul 31 2002
11 comments
1,896 views