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