Java tutorial
//package com.java2s; import javafx.application.Platform; import java.util.concurrent.ExecutionException; import java.util.concurrent.FutureTask; public class Main { /** * Runs the given <tt>Runnable</tt> on the JavaFX Application Thread. The method blocks until the <tt>Runnable</tt> is executed completely. * You should use the {@link io.datafx.core.concurrent.ProcessChain} for concurrent tasks and background tasks * instead of using this low level API. * * * @param runnable the runnable that will be executed on the JavaFX Application Thread * @throws InterruptedException if the JavaFX Application Thread was interrupted while waiting * @throws ExecutionException if the call of the run method of the <tt>Runnable</tt> threw an exception */ public static void runAndWait(Runnable runnable) throws InterruptedException, ExecutionException { FutureTask<Void> future = new FutureTask<>(runnable, null); Platform.runLater(future); future.get(); } }