<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    While it might be possible to make the shutdown experience a little
    more graceful, your expectation of being able to use the GUI after
    the start of the shutdown sequence is unlikely to be met. Quoting
    from the shutdown docs [1] :<br>
    <br>
    "Shutdown hooks run at a delicate time in the life cycle of a
    virtual machine ... Attempts to use other thread-based services such
    as the AWT event-dispatch thread, for example, may lead to
    deadlocks.<br>
    <br>
    Shutdown hooks should also finish their work quickly. When a program
    invokes exit, the expectation is that the virtual machine will
    promptly shut down and exit. When the virtual machine is terminated
    due to user logoff or system shutdown the underlying operating
    system may only allow a limited amount of time in which to shut down
    and exit. <b>It is therefore inadvisable to attempt any user
      interaction or to perform a long-running computation in a shutdown
      hook.</b>"<br>
    <br>
    Note, particularly, that last sentence. Asking JavaFX to ignore the
    fact that there is a shutdown in progress doesn't change that.
    Having said that, I can take another look at this (not right away,
    though) and see what else we can do.<br>
    <br>
    -- Kevin<br>
    <br>
    [1]
<a class="moz-txt-link-freetext" href="https://docs.oracle.com/en/java/javase/22/docs/api/java.base/java/lang/Runtime.html#addShutdownHook(java.lang.Thread)">https://docs.oracle.com/en/java/javase/22/docs/api/java.base/java/lang/Runtime.html#addShutdownHook(java.lang.Thread)</a><br>
    <br>
    <br>
    <div class="moz-cite-prefix">On 7/26/2024 10:11 AM, PavelTurk wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:015ba9f6-e266-4fb3-bda0-32654f12af23@gmail.com">Hello,
      Kevin
      <br>
      <br>
      Yes, I filed that enhancement request.
      <br>
      <br>
      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
<a class="moz-txt-link-freetext" href="https://urldefense.com/v3/__https://stackoverflow.com/a/4047975__;!!ACWV5N9M2RV99hQ!Kubf8U462HbtwSv0HaNgAZNyYpFS94_WfV0T8TAjTcNx56xb2lUr9jPR5ezZHSUjZ1C-tStV9j5KxWUduzx7XjC0BR1D$">https://urldefense.com/v3/__https://stackoverflow.com/a/4047975__;!!ACWV5N9M2RV99hQ!Kubf8U462HbtwSv0HaNgAZNyYpFS94_WfV0T8TAjTcNx56xb2lUr9jPR5ezZHSUjZ1C-tStV9j5KxWUduzx7XjC0BR1D$</a>
      ).
      <br>
      <br>
      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.
      <br>
      <br>
      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.
      <br>
      <br>
      Best regards, Pavel
      <br>
      <br>
      <br>
      On 7/26/24 16:54, Kevin Rushforth wrote:
      <br>
      <blockquote type="cite">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()).
        <br>
        <br>
        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).
        <br>
        <br>
        Related to this, I see that someone (perhaps it was you?) just
        filed an enhancement request to consider optionally disabling
        the shutdown hook:
        <br>
        <br>
        <a class="moz-txt-link-freetext" href="https://bugs.openjdk.org/browse/JDK-8337247">https://bugs.openjdk.org/browse/JDK-8337247</a>
        <br>
        <br>
        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:
        <br>
        <br>
        --------------------------------------------------
        <br>
        “I can take a look, but I do not think we will implement this
        Enhancement request -- at least not as described.
        <br>
        <br>
        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:
        <br>
        <br>
        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)
        <br>
        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.
        <br>
        <br>
        There might be other solutions.”
        <br>
        -------------------------------------------------------
        <br>
        <br>
        -- Kevin
        <br>
        <br>
        <br>
        On 7/25/2024 8:43 AM, PavelTurk wrote:
        <br>
        <blockquote type="cite">Hello all.
          <br>
          <br>
          JavaFX adds its own shutdown hook. That gives many problems
          when it is necessary to work with application,
          <br>
          when system is shutting down, for example, if user presses
          CTRL+C. The first problem I described here -
          <br>
          <a class="moz-txt-link-freetext" href="https://bugs.openjdk.org/browse/">https://bugs.openjdk.org/browse/</a>
          <br>
          <br>
          Another problem is that after pressing CTRL+C JavaFX seems not
          to respond anymore. For example I've
          <br>
          observed that if after that we try to do Platform.runLater(()
          -> myCode is here), then myCode will never execute.
          <br>
          So, it is necessary to check in system, how it is shutting
          down, if it is. And this problem creates other problems.
          <br>
          <br>
          Before opening a feature request, I decided to ask JavaFX
          developers, if it possible to disable JavaFX shutdown hook.
          <br>
          I mean, if there is no system property (something like
          javafx.shutdownhook.disabled), it will be added, but if I want
          <br>
          to call Platform.exit() manually I want to be able to disable
          JavaFX shutdown hook.
          <br>
          <br>
          Best regards, Pavel
          <br>
          <br>
        </blockquote>
        <br>
      </blockquote>
      <br>
    </blockquote>
    <br>
  </body>
</html>