Search in sources :

Example 1 with Dispatch

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();
}
Also used : FutureTask(java.util.concurrent.FutureTask) Dispatch(com.apple.concurrent.Dispatch) AWTError(java.awt.AWTError) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

Dispatch (com.apple.concurrent.Dispatch)1 AWTError (java.awt.AWTError)1 ExecutionException (java.util.concurrent.ExecutionException)1 FutureTask (java.util.concurrent.FutureTask)1