I am not sure we will want to disabling the shutdown hook, since that is likely to cause problems (they were added to fix bugs that resulted from applications calling System.exit()).

In the bug report for JDK-8320923, you mentioned that Swing doesn't have this problem, but that's because Swing closes all of its windows before effecting the shutdown (that's something JavaFX could do as well).

Related to this, I see that someone (perhaps it was you?) just filed an enhancement request to consider optionally disabling the shutdown hook:

https://bugs.openjdk.org/browse/JDK-8337247

I haven't looked at it closely, but my sense is that disabling the shutdown hooks in a way that tries to keep the JavaFX runtime active is unlikely to be something we want to do.  I added the following comment to the above JBS issue with some initial thoughts:

--------------------------------------------------
“I can take a look, but I do not think we will implement this Enhancement request -- at least not as described.

Instead, we might consider whether this can be done using existing mechanisms, such as overriding Application::exit. If it turns out there isn't a suitable existing mechanism, we might consider other solutions. A couple possibilities:

1. Provide a Platform setting that will cause Platform.runLater to throw an exception if called after shutdown (this might be require adding a few try/catch blocks in our own cleanup code) 2. Rather than a setting as described above, create a new overload of Platform.runLater that throws an exception if the Platform is not able to queue the request.

There might be other solutions.”
-------------------------------------------------------

-- Kevin


On 7/25/2024 8:43 AM, PavelTurk wrote:
Hello all.

JavaFX adds its own shutdown hook. That gives many problems when it is necessary to work with application, when system is shutting down, for example, if user presses CTRL+C. The first problem I described here -
https://bugs.openjdk.org/browse/

Another problem is that after pressing CTRL+C JavaFX seems not to respond anymore. For example I've observed that if after that we try to do Platform.runLater(() -> myCode is here), then myCode will never execute. So, it is necessary to check in system, how it is shutting down, if it is. And this problem creates other problems.

Before opening a feature request, I decided to ask JavaFX developers, if it possible to disable JavaFX shutdown hook. I mean, if there is no system property (something like javafx.shutdownhook.disabled), it will be added, but if I want to call Platform.exit() manually I want to be able to disable JavaFX shutdown hook.

Best regards, Pavel


Reply via email to