Unfortunately, calling it from the EDT creates a deadlock.
SciJava Common registers a JVM shutdown hook thread that calls dispose() on AWT windows it manages (e.g. the main ImageJ2 window), but Window#dispose() internally runs some logic via EventQueue.invokeAndWait.
But meanwhile, the System.exit call triggers the shutdown hooks, which use Thread#join to wait for them to finish, thus blocking the EDT. So the invokeAndWait disposing the window can never finish.
Therefore, as a workaround here, we avoid the problem by exiting the JVM from a new thread instead.
Unfortunately, calling it from the EDT creates a deadlock.
SciJava Common registers a JVM shutdown hook thread that calls
dispose()
on AWT windows it manages (e.g. the main ImageJ2 window), butWindow#dispose()
internally runs some logic viaEventQueue.invokeAndWait
.But meanwhile, the
System.exit
call triggers the shutdown hooks, which useThread#join
to wait for them to finish, thus blocking the EDT. So theinvokeAndWait
disposing the window can never finish.Therefore, as a workaround here, we avoid the problem by exiting the JVM from a new thread instead.
Might fix #538.