Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid calling System.exit from the EDT #575

Merged
merged 1 commit into from
Apr 16, 2024
Merged

Conversation

ctrueden
Copy link
Member

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.

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.
@skalarproduktraum skalarproduktraum merged commit 70f1c7f into main Apr 16, 2024
4 checks passed
@skalarproduktraum skalarproduktraum deleted the fix/shutdown-hang branch April 16, 2024 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sciview hangs on shutdown from Main.kt
2 participants