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

An Executor for JavaFX

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 8u45
    • javafx
    • JDK 8u45, Win 8.1, 64 Bit

      Thanks to Java SE 8's CompletableFuture it is possible to do low-level reactive programming style in Java. With JavaFX this is a bit cumbersome, as there is not Executor for JavaFX.

      I like to propose to add the following code to the Platform class:

      ```
      public static final Executor JAVA_FX = Platform::runAsJavaFX;

      public static final void runAsJavaFX(final Runnable runnable) {
      if (Platform.isFxApplicationThread())
      runnable.run();
      else
      Platform.runLater(runnable);
      }
      ```

      This makes it pretty simple and readable to use CompletableFuture with Java FX, hence allowing totally simple background tasks done by the Java SE's shared thread pool:

      ```
      CompletableFuture.supplyAsync(backgroundTask).thenAcceptAsync(javaFxTask, JAVA_FX);
      ```

            Unassigned Unassigned
            mkarg Markus Karg
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: