Is it possible to disable JavaFX shutdown hook?
PavelTurk
pavelturk2000 at gmail.com
Fri Jul 26 17:11:54 UTC 2024
Hello, Kevin
Yes, I filed that enhancement request.
When user presses CTRL+C then SIGINT signal is sent to the process. SIGINT is a signal used to request a graceful termination of a process, typically initiated by the user(more details are here https://stackoverflow.com/a/4047975).
Now, we are talking about GUI application (if we didn't develop a GUI application, we wouldn't need JavaFX, would we?). So, our GUI application gets SIGINT or SIGTERM (I didn't test with SIGTERM, but I think result is the same) and after that immediately stops working because of the damned shutdown hook. For example, if our application is a simple text editor, our application can't let user save file. Why? Because GUI platform doesn't work anymore.
That's why I opened that issue. I saw you suggested working with exceptions. But that issue is not about exceptions, but about letting application developers control when to shutdown platform.
Best regards, Pavel
On 7/26/24 16:54, Kevin Rushforth wrote:
> 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
>>
>
More information about the openjfx-dev
mailing list