use of com.apple.concurrent.Dispatch in project jdk8u_jdk by JetBrains.
the class CThreading method executeOnAppKit.
public static <V> V executeOnAppKit(Callable<V> command) throws Throwable {
if (!isAppKit()) {
Dispatch dispatch = Dispatch.getInstance();
if (dispatch == null) {
throw new AWTError("Could not get Dispatch object");
}
FutureTask<V> future = new FutureTask<>(command);
dispatch.getNonBlockingMainQueueExecutor().execute(future);
try {
return future.get();
} catch (InterruptedException e) {
throw new AWTError(e.getMessage());
} catch (ExecutionException e) {
throw e.getCause();
}
} else
return command.call();
}
Aggregations