JVM won't stop

I have a simple test run of some code of medium complexity that will not be completed, i.e. the main method ends, but the process does not die.

Here is a summary of the code (which is too long to insert here):

  • ProcessBuilder used to create a group of subprocesses. They all do the right thing (if you can believe VisualVM).
  • We use log4j.
  • The main algorithm is executed inside FutureTask , on which run and later get called.
  • We are not explicitly using RMI, although the thread list seems to offer this.

Obviously, I can call System.exit(0) , but I would like to know what is wrong here. I could not create a minimal unsuccessful example. In addition, I cannot identify the obvious culprit from the list of threads; maybe you can?

from VisualVM after main terminates

Edit: See here for a stream dump.

+4
source share
2 answers

Scorpio led me to the correct answer:

RMI Reaper is a bit of a garbage collector for remote objects, for example. instances (subclasses) of UnicastRemoteObject . This is a non-daemon thread and therefore blocks the JVM termination if there are still exported objects that cannot be cleared.

You can force removal of deleted objects in this sense by passing them UnicastRemoteObject.unexportObject(., true) . If you do this on all previously exported objects, the RMI Reaper terminates and the JVM can be disabled.

+4
source

You mentioned FutureTask. The first thing that comes to my mind: do you use ExecutorService and forget to close it?

The second thing that comes to my mind: do you read all the threads from the process to the end? I have been working with subprocesses for a long time, and I don’t remember exactly, but. I had problems similar to what you described, and, reading the streams to the end, the problem will disappear covertly!

+2
source

All Articles