<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <font face="Helvetica, Arial, sans-serif">I'd like to hear from the
      others on this. I don't see any fundamental problem with having
      the play/pause/stop methods wrap their implementation in a
      runLater (if not on the FX Application thread already), and
      documenting that it does so, if we can get general agreement.<br>
      <br>
      -- Kevin<br>
      <br>
      <br>
    </font>
    <div class="moz-cite-prefix">On 1/24/2024 5:29 AM, Jurgen Doll
      wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:op.2h1zrpqn0ae2rt@admin-pc">
      
      <style type="text/css">body { font-family:'Calibri'; font-size:13px}</style>
      <div><big>Hi Kevin</big></div>
      <div><big><br>
        </big></div>
      <div><big>If I may make one more final appeal then to an
          alternative solution please.</big></div>
      <div><big><br>
        </big></div>
      <div><big>Could we then instead of throwing an Exception rather
          invoke runLater if needed inside play, stop, and resume.</big></div>
      <div><big><br>
        </big></div>
      <div><big>Putting the onus on the developer is fine if it is the
          developer that is invoking the call, but if it's in a library
          then it's a no go.</big><big><br>
        </big><big><br>
        </big><big>In my application I have two libraries that I know of
          where this happens. The major problem is that with FX22 as it
          now stands my </big><big>application just crashes because
          play() does an FX thread check and throws an Exception which
          it never did before. There are bound </big><big>to be other
          applications out there that are going to find themselves in a
          similar position.</big></div>
      <div><big><br>
        </big></div>
      <div><big>PLEASE !</big></div>
      <div><big><br>
        </big></div>
      <div><big>Regards</big></div>
      <div><big>Jurgen</big></div>
      <div><big><br>
        </big></div>
      <div><br>
      </div>
      <div><br>
      </div>
      <div>On Wed, 24 Jan 2024 15:15:31 +0200, Kevin Rushforth
        <a class="moz-txt-link-rfc2396E" href="mailto:kevin.rushforth@oracle.com"><kevin.rushforth@oracle.com></a> wrote:<br>
      </div>
      <br>
      <blockquote style="margin: 0 0 0.80ex; border-left: #0000FF 2px solid; padding-left: 1ex">
        Thank you to Jurgen for raising the question and to Nir, John,
        and Michael for evaluating it.<br>
        <br>
        I conclude that there is insufficient motivation to revert the
        change in behavior implemented by JDK-8159048 to allow calling
        the play/pause/stop methods of Animation on a background thread.
        Doing so without making it fully multi-thread-safe would be
        asking for problems, and making it fully multi-thread-safe would
        be a fair bit of work to do it right without a clear benefit.<br>
        <br>
        We will proceed with the current approach and let JDK-8159048
        stand. Further, we will proceed with <a class="moz-txt-link-freetext" href="https://bugs.openjdk.org/browse/JDK-8324219" moz-do-not-send="true">https://bugs.openjdk.org/browse/JDK-8324219</a>
        which is under review in <a class="moz-txt-link-freetext" href="https://github.com/openjdk/jfx/pull/1342" moz-do-not-send="true">https://github.com/openjdk/jfx/pull/1342</a><br>
        <br>
        -- Kevin<br>
        <br>
        <div class="moz-cite-prefix">On 1/24/2024 12:30 AM, Nir Lisker
          wrote:<br>
        </div>
        <blockquote type="cite" cite="mid:CA+0ynh88b4=5A5DHF__xMaS0wPvE7HyhMFoqeAPV7pFCHBGgYQ@mail.gmail.com">
          <div dir="auto">After playing around with the code sample, I
            think that this is not the right way to use the animation.
            The reason is that there is no point in starting the
            animation before the control is attached to the scenegraph,
            or even made visible. A small refactoring where, e.g., the
            controller class exposes a method to start the animation in
            onSucceeded or just calls it on the FX thread is enough. I
            never start an animation as part of the construction because
            it's not the right time. John suggested tying the lifecycle
            of the animation to the showing of the node, which also
            solves the problem. 
            <div dir="auto"><br>
            </div>
            <div dir="auto">There are animations like PauseTransition or
              other non-interfering Timelines that could reasonably be
              run on a background thread. Or maybe just on an
              unconnected control. This could be a reason to not limit
              animation methods to the FX thread at the expense of
              possible user errors, but document the pitfall.</div>
            <div dir="auto"><br>
            </div>
            <div dir="auto">I don't see a good use case for modifying
              controls in a background thread while still interacting
              with the scenegraph, hence for adding multithread
              support. </div>
            <div dir="auto"><br>
            </div>
            <div dir="auto">- Nir</div>
          </div>
          <br>
          <div class="gmail_quote">
            <div dir="ltr" class="gmail_attr">On Mon, Jan 22, 2024,
              12:59 Jurgen Doll <<a href="mailto:javafx@ivoryemr.co.za" moz-do-not-send="true" class="moz-txt-link-freetext">javafx@ivoryemr.co.za</a>>
              wrote:<br>
            </div>
            <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
              <div>
                <div><big>Here's an example as requested by Nir:</big></div>
                <div><big><br>
                  </big></div>
                <div><span style="color:#7f0055;font-weight:bold">public</span><span style="color:#000000"> </span><span style="color:#7f0055;font-weight:bold">class</span><span style="color:#000000"> FxTimeLineTest </span><span style="color:#7f0055;font-weight:bold">extends</span><span style="color:#000000"> Application</span></div>
                <div>
                  <div style="background-color:#ffffff;padding:0px 2px 0px 2px">
                    <div style="color:#000000;background-color:#ffffff;font-family:"Consolas";font-size:10pt;white-space:pre-wrap"><p style="margin:0"><span style="color:#000000">{</span></p><p style="margin:0"><span style="color:#000000">    </span><span style="color:#7f0055;font-weight:bold">private</span><span style="color:#000000"> BorderPane </span><span style="color:#0000c0">bp</span><span style="color:#000000"> = </span><span style="color:#7f0055;font-weight:bold">new</span><span style="color:#000000"> BorderPane( </span><span style="color:#7f0055;font-weight:bold">new</span><span style="color:#000000"> Label(</span><span style="color:#2a00ff">"Loading"</span><span style="color:#000000">) );</span></p><p style="margin:0">
</p><p style="margin:0"><span style="color:#000000">    </span><span style="color:#7f0055;font-weight:bold">public</span><span style="color:#000000"> </span><span style="color:#7f0055;font-weight:bold">static</span><span style="color:#000000"> </span><span style="color:#7f0055;font-weight:bold">void</span><span style="color:#000000"> main( String[] </span><span style="color:#6a3e3e">args</span><span style="color:#000000"> ) {</span></p><p style="margin:0"><span style="color:#000000">        </span><span style="color:#000000;font-style:italic">launch</span><span style="color:#000000">( FxTimeLineTest.</span><span style="color:#7f0055;font-weight:bold">class</span><span style="color:#000000">, </span><span style="color:#6a3e3e">args</span><span style="color:#000000"> );</span></p><p style="margin:0"><span style="color:#000000">    }</span></p><p style="margin:0">
</p><p style="margin:0"><span style="color:#000000">    </span><span style="color:#646464">@Override</span></p><p style="margin:0"><span style="color:#000000">    </span><span style="color:#7f0055;font-weight:bold">public</span><span style="color:#000000"> </span><span style="color:#7f0055;font-weight:bold">void</span><span style="color:#000000"> start( Stage </span><span style="color:#6a3e3e">primaryStage</span><span style="color:#000000"> ) </span><span style="color:#7f0055;font-weight:bold">throws</span><span style="color:#000000"> Exception {</span></p><p style="margin:0"><span style="color:#000000">        </span><span style="color:#7f0055;font-weight:bold">new</span><span style="color:#000000"> Thread( </span><span style="color:#7f0055;font-weight:bold">new</span><span style="color:#000000"> LoadScene() ).start();</span></p><p style="margin:0"><span style="color:#000000">        </span><span style="color:#6a3e3e">primaryStage</span><span style="color:#000000">.setScene( </span>
 <span style="color:#7f0055;font-weight:bold">new</span><span style="color:#000000"> Scene( </span><span style="color:#0000c0">bp</span><span style="color:#000000">, 300, 200 ) );</span></p><p style="margin:0"><span style="color:#000000">        </span><span style="color:#6a3e3e">primaryStage</span><span style="color:#000000">.setTitle( </span><span style="color:#2a00ff">"Memory Usage"</span><span style="color:#000000"> );</span></p><p style="margin:0"><span style="color:#000000">        </span><span style="color:#6a3e3e">primaryStage</span><span style="color:#000000">.show();</span></p><p style="margin:0"><span style="color:#000000">    }</span></p><p style="margin:0">
</p><p style="margin:0"><span style="color:#000000">    </span><span style="color:#7f0055;font-weight:bold">private</span><span style="color:#000000"> </span><span style="color:#7f0055;font-weight:bold">class</span><span style="color:#000000"> LoadScene </span><span style="color:#7f0055;font-weight:bold">extends</span><span style="color:#000000"> Task<Parent> {</span></p><p style="margin:0"><span style="color:#000000">        </span><span style="color:#646464">@Override</span><span style="color:#000000"> </span><span style="color:#7f0055;font-weight:bold">protected</span><span style="color:#000000"> Parent call() </span><span style="color:#7f0055;font-weight:bold">throws</span><span style="color:#000000"> Exception {</span></p><p style="margin:0"><span style="color:#000000">            Parent </span><span style="color:#6a3e3e">p</span><span style="color:#000000"> = FXMLLoader.</span><span style="color:#000000;font-style:italic">load</span><span style="color:#000000">( getClass(
 ).getResource(</span><span style="color:#2a00ff">"TestView.fxml"</span><span style="color:#000000">) );</span></p><p style="margin:0"><span style="color:#000000">            Thread.</span><span style="color:#000000;font-style:italic">sleep</span><span style="color:#000000">( 1000 );</span></p><p style="margin:0"><span style="color:#000000">            </span><span style="color:#7f0055;font-weight:bold">return</span><span style="color:#000000"> </span><span style="color:#6a3e3e">p</span><span style="color:#000000">;</span></p><p style="margin:0"><span style="color:#000000">        }</span></p><p style="margin:0">
</p><p style="margin:0"><span style="color:#000000">        </span><span style="color:#646464">@</span><span style="color:#646464">Override</span><span style="color:#000000"> </span><span style="color:#7f0055;font-weight:bold">protected</span><span style="color:#000000"> </span><span style="color:#7f0055;font-weight:bold">void</span><span style="color:#000000"> succeeded() {</span></p><p style="margin:0"><span style="color:#000000">            </span><span style="color:#0000c0">bp</span><span style="color:#000000">.setCenter( getValue() );</span></p><p style="margin:0"><span style="color:#000000">        }</span></p><p style="margin:0">
</p><p style="margin:0"><span style="color:#000000">        </span><span style="color:#646464">@</span><span style="color:#646464">Override</span><span style="color:#000000"> </span><span style="color:#7f0055;font-weight:bold">protected</span><span style="color:#000000"> </span><span style="color:#7f0055;font-weight:bold">void</span><span style="color:#000000"> failed() {</span></p><p style="margin:0"><span style="color:#000000">            getException().printStackTrace();</span></p><p style="margin:0"><span style="color:#000000">        }</span></p><p style="margin:0"><span style="color:#000000">    }</span></p><p style="margin:0"><span style="color:#000000">}

</span></p></div>
                  </div>
                </div>
                <div>
                  <div style="background-color:#ffffff;padding:0px 2px 0px 2px">
                    <div style="color:#000000;background-color:#ffffff;font-family:"Consolas";font-size:10pt;white-space:pre-wrap"><p style="margin:0">------------------------------------------------------------------------------------------------------</p></div>
                  </div>
                </div>
                <div><br>
                </div>
                <div>
                  <div style="background-color:#ffffff;padding:0px 2px 0px 2px">
                    <div style="color:#000000;background-color:#ffffff;font-family:"Consolas";font-size:10pt;white-space:pre-wrap"><p style="margin:0"><span style="color:#7f0055;font-weight:bold">public</span><span style="color:#000000"> </span><span style="color:#7f0055;font-weight:bold">class</span><span style="color:#000000"> TestView</span></p><p style="margin:0"><span style="color:#000000">{</span></p><p style="margin:0"><span style="color:#000000">    </span><span style="color:#646464">@</span><span style="color:#646464">FXML</span><span style="color:#000000"> </span><span style="color:#7f0055;font-weight:bold">private</span><span style="color:#000000"> Label </span><span style="color:#0000c0">memory</span><span style="color:#000000">;</span></p><p style="margin:0">
</p><p style="margin:0"><span style="color:#000000">    </span><span style="color:#7f0055;font-weight:bold">private</span><span style="color:#000000"> </span><span style="color:#7f0055;font-weight:bold">static</span><span style="color:#000000"> </span><span style="color:#7f0055;font-weight:bold">final</span><span style="color:#000000"> </span><span style="color:#7f0055;font-weight:bold">double</span><span style="color:#000000">  </span><span style="color:#0000c0;font-style:italic;font-weight:bold">MEGABYTE</span><span style="color:#000000"> = 1024 * 1024;</span></p><p style="margin:0">
</p><p style="margin:0"><span style="color:#000000">    </span><span style="color:#646464">@</span><span style="color:#646464">FXML</span><span style="color:#000000"> </span><span style="color:#7f0055;font-weight:bold">private</span><span style="color:#000000"> </span><span style="color:#7f0055;font-weight:bold">void</span><span style="color:#000000"> initialize()</span></p><p style="margin:0"><span style="color:#000000">    {</span></p><p style="margin:0"><span style="color:#000000">        </span><span style="color:#7f0055;font-weight:bold">var</span><span style="color:#000000"> </span><span style="color:#6a3e3e">updater</span><span style="color:#000000"> = </span><span style="color:#7f0055;font-weight:bold">new</span><span style="color:#000000"> Timeline</span></p><p style="margin:0"><span style="color:#000000">        (</span></p><p style="margin:0"><span style="color:#000000">            </span><span style="color:#7f0055;font-weight:bold">new</span><span style="color:#000000"> K
 eyFrame( Duration.</span><span style="color:#000000;font-style:italic">seconds</span><span style="color:#000000">(2.5), </span><span style="color:#6a3e3e">event</span><span style="color:#000000"> -></span></p><p style="margin:0"><span style="color:#000000">            {</span></p><p style="margin:0"><span style="color:#000000">                </span><span style="color:#7f0055;font-weight:bold">var</span><span style="color:#000000"> </span><span style="color:#6a3e3e">runtime</span><span style="color:#000000"> = Runtime.</span><span style="color:#000000;font-style:italic">getRuntime</span><span style="color:#000000">();</span></p><p style="margin:0"><span style="color:#000000">                </span><span style="color:#7f0055;font-weight:bold">double</span><span style="color:#000000"> </span><span style="color:#6a3e3e">maxMemory</span><span style="color:#000000"> = </span><span style="color:#6a3e3e">runtime</span><span style="color:#000000">.maxMemory() / </span><span style="color:
 #0000c0;font-style:italic;font-weight:bold">MEGABYTE</span><span style="color:#000000">;</span></p><p style="margin:0"><span style="color:#000000">                </span><span style="color:#7f0055;font-weight:bold">double</span><span style="color:#000000"> </span><span style="color:#6a3e3e">usedMemory</span><span style="color:#000000"> = (</span><span style="color:#6a3e3e">runtime</span><span style="color:#000000">.totalMemory() - </span><span style="color:#6a3e3e">runtime</span><span style="color:#000000">.freeMemory()) / </span><span style="color:#0000c0;font-style:italic;font-weight:bold">MEGABYTE</span><span style="color:#000000">;</span></p><p style="margin:0"><span style="color:#000000">                </span><span style="color:#0000c0">memory</span><span style="color:#000000">.setText( (</span><span style="color:#7f0055;font-weight:bold">int</span><span style="color:#000000">) </span><span style="color:#6a3e3e">usedMemory</span><span style="color:#000000"> + </span><span styl="" e="color:#2a00ff">" MB / "</span><span style="color:#000000"> + (</span><span style="color:#7f0055;font-weight:bold">int</span><span style="color:#000000">) </span><span style="color:#6a3e3e">maxMemory</span><span style="color:#000000"> +</span><span style="color:#2a00ff">" MB"</span><span style="color:#000000"> );</span></p><p style="margin:0"><span style="color:#000000">            })</span></p><p style="margin:0"><span style="color:#000000">        );</span></p><p style="margin:0">
</p><p style="margin:0"><span style="color:#000000">        </span><span style="color:#6a3e3e">updater</span><span style="color:#000000">.setCycleCount(Animation.</span><span style="color:#0000c0;font-style:italic;font-weight:bold">INDEFINITE</span><span style="color:#000000">);
        // This FXML is being loaded on a background thread
</span></p><p style="margin:0"><span style="color:#000000">        </span><span style="color:#6a3e3e">updater</span><span style="color:#000000">.play();</span></p><p style="margin:0"><span style="color:#000000">    }</span></p><p style="margin:0"><span style="color:#000000">}

</span></p></div>
                  </div>
                </div>
                <div>
                  <div style="background-color:#ffffff;padding:0px 2px 0px 2px">
                    <div style="color:#000000;background-color:#ffffff;font-family:"Consolas";font-size:10pt;white-space:pre-wrap"><p style="margin:0">------------------------------------------------------------------------------------------------------</p></div>
                  </div>
                </div>
                <div><br>
                </div>
                <div> <span style="color:#000000"><big>TestView.fxml</big></span>
                </div>
                <div><br>
                </div>
                <div>
                  <div style="background-color:#ffffff;padding:0px 2px 0px 2px">
                    <div style="color:#000000;background-color:#ffffff;font-family:"Consolas";font-size:10pt;white-space:pre-wrap"><div style="background-color:#ffffff;padding:0px 2px 0px 2px"><div style="color:#000000;background-color:#ffffff;font-family:"Consolas";font-size:10pt;white-space:pre-wrap"><p style="margin:0"><?xml version="1.0" encoding="UTF-8"?></p><p style="margin:0">
</p><p style="margin:0"><?import javafx.scene.control.Label?></p><p style="margin:0"><?import javafx.scene.layout.StackPane?></p><p style="margin:0">
</p><p style="margin:0"><StackPane xmlns:fx="<a href="http://javafx.com/fxml/1" target="_blank" rel="noreferrer" moz-do-not-send="true" class="moz-txt-link-freetext">http://javafx.com/fxml/1</a>" fx:controller="TestView"></p><p style="margin:0">   <children></p><p style="margin:0">      <Label fx:id="memory" text="Current / Max MB" ></p><p style="margin:0">         <properties hashCode="12345" /></p><p style="margin:0">      </Label></p><p style="margin:0">   </children></p><p style="margin:0"></StackPane></p></div></div></div>
                  </div>
                </div>
                <div><br>
                </div>
                <div><br>
                </div>
                <div><br>
                </div>
                <div>On Sat, 20 Jan 2024 17:08:41 +0200, Nir Lisker <<a href="mailto:nlisker@gmail.com" target="_blank" rel="noreferrer" moz-do-not-send="true" class="moz-txt-link-freetext">nlisker@gmail.com</a>>
                  wrote:<br>
                </div>
                <br>
                <blockquote style="margin:0 0 0.80ex;border-left:#0000ff 2px solid;padding-left:1ex">
                  <div dir="ltr">Hi Jurgen,
                    <div><br>
                    </div>
                    <div>What I'm confused about the most is what it is
                      you are actually trying to do that
                      necessitates the use of animations outside of the
                      FX thread. You said that you need to initialize
                      controls on another thread, and that you are using
                      Task (both of which are fine), but how does
                      playing animations relate? Playing an animation is
                      something that is done explicitly, usually in
                      order to manipulate data. Can you give a real use
                      case, like a minimized version of what you're
                      doing?</div>
                    <div><br>
                    </div>
                    <div>- Nir</div>
                  </div>
                </blockquote>
              </div>
            </blockquote>
          </div>
        </blockquote>
        <br>
      </blockquote>
      <br>
      <br>
      <br>
      <div id="M2Signature">
        <div>-- </div>
        <div>Using Opera's mail client: <a href="http://www.opera.com/mail/" moz-do-not-send="true" class="moz-txt-link-freetext">http://www.opera.com/mail/</a></div>
      </div>
    </blockquote>
    <br>
  </body>
</html>