Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8140590

[Platform] Provide a method to run something in FX Thread and wait for it to finish

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • None
    • javafx
    • None

      We have some parts in our code where we want to run some code in the FX Thread not later but immediately and to get exceptions thrown in the executed code.

      We wrote a helper to realize this and it is very useful, maybe you can integrate it into JavaFX:

      public static void run(Runnable runnable) {
      if (Platform.isFxApplicationThread()) {
      throw new IllegalStateException("Should NOT be invoked from FX Thread!");
      }
      CompletableFuture<Exception> runLaterPerformed = new CompletableFuture<>();
      Runnable internalRunnable = new Runnable() {
      @Override
      public void run() {
      Exception exception = null;
      try {
      runnable.run();
      } catch (Exception e) {
      exception = e;
      }
      runLaterPerformed.complete(exception);
      }
      };
      Platform.runLater(internalRunnable);
      Exception exception = runLaterPerformed.get();
      if (exception != null) {
      throw exception;
      }
      }

            kcr Kevin Rushforth
            aliebelt Andreas Liebelt
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: