Java tutorial
//package com.java2s; import java.lang.reflect.InvocationTargetException; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.FutureTask; import static javax.swing.SwingUtilities.invokeAndWait; public class Main { public static <T> T callAndWait(final Callable<T> callable) throws InvocationTargetException, InterruptedException, ExecutionException { final FutureTask<T> futureTask = new FutureTask<>(callable); invokeAndWait(futureTask); return futureTask.get(); } }