Java3D starts several system threads and doesn't set the isDaemon flag on them. When I dispose the (only) JFrame of my application it won't terminate because these threads are still running.
Calling System.exit() seems to be the only way to terminate the application. (Or killing it from outside, of course).
As I don't like to call System.exit() I have tried the following (but without success):
- calling removeAllLocales() on the VirtualUniverse: This terminates most of the threads, but still there is one (named J3D-Renderer-1) remaining.
- using reflection to obtain a reference to the the field ThreadGroup rootThreadGroupp in javax.media.j3d.MasterControl and settting isDeamon true on that ThreadGroup. This didn't seem to have any effect.
- geting a reference to the ThreadGroup named "Java3D" and calling interrupt() on it: This caused the java3d threads to write InterruptedException to stderr, but nothing else.
- locate the sources of the Java3d-core library and propose a patch: I found a repository here: https://github.com/hharrison/java3d-core and here: https://java.net/projects/j3d-core/sources . The later one looks "official" but shows the last change in it happened 5 years ago and the former one looks like a private fork to me.
I am close to giving up and make that call to System.exit(), but I still don't like it. Do you know a better way?