scenerygraphics / sciview

sciview is a tool for visualization and interaction with ND image and mesh data
BSD 2-Clause "Simplified" License
62 stars 17 forks source link

Avoid calling System.exit from the EDT #575

Closed ctrueden closed 2 months ago

ctrueden commented 2 months ago

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.

Might fix #538.