JDK-8091784 : I would like an extension to Wait for the FX Thread
  • Type: Enhancement
  • Component: javafx
  • Sub-Component: application-lifecycle
  • Affected Version: 7u40
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • Submitted: 2013-09-13
  • Updated: 2017-05-18
  • Resolved: 2017-05-18
Related Reports
Relates :  
Relates :  
Description
If you wait while using the FX Thread, the wait hangs on to the thread and everything stops.

What would be nice is an extension to Wait that puts the current thread status etc on
the "run later queue" marked as "non executable". The FX thread is then released to do other
things. When the Wait is "notified", the status is changed to  "executable" and run later.

I know it is not that simple but it might make complex, asynchronous animation a bit
easier to program.

Regards
Don
Comments
The requested functionality as specified is unimplementable using the syntax provided -- putting a Java thread to sleep or calling wait will block that thread. If I understand the request, however, the need can be satisfied by using nested event loops which are implemented in JDK 9 by JDK-8090865.
18-05-2017

Hi, This is a not very complicated solution to this problem. It tries to shows what is required Don ------ package tests; import javafx.application.Application; import javafx.application.Platform; import javafx.stage.Stage; public class FXThreadTest extends Application { FXThreadTest fxtt = this; TTT ttt = new TTT(); Stage stage; public void tst() { Thread lt = new Thread(ttt); System.out.println("tst started"); lt.start(); // now do other things with this thread try { Thread.sleep(5000); } catch(Exception e) { e.printStackTrace(); } System.out.println("tst terminate Platform"); Platform.exit(); System.out.println("tst join"); try { lt.join(); } catch(Exception e) { e.printStackTrace(); } System.out.println("tst ending"); } public void start(Stage stage) { System.out.println("start started"); this.stage = stage; // fx thread - don't hang on to it - use runLater System.out.println("start finish - fx thread free"); } public void lnch() { System.out.println("lnch started - issue launch"); launch(); System.out.println("lnch ended"); } public class TTT implements Runnable { public void run() { System.out.println("run started"); System.out.println("run call lnch"); fxtt.lnch(); System.out.println("run return from lnch"); } } public static void main(String[] args) { FXThreadTest fxtt = new FXThreadTest(); System.out.println("main started"); fxtt.tst(); System.out.println("main ending"); } } Printout main started tst started run started run call lnch lnch started - issue launch start started start finish - fx thread free tst terminate Platform tst join lnch ended run return from lnch tst ending main ending
15-09-2013

Something to explore for a future release.
14-09-2013