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

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: javafx
    • Labels:
      None

      Description

      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;
      }
      }

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: