Example usage for java.util.concurrent CompletionException CompletionException

List of usage examples for java.util.concurrent CompletionException CompletionException

Introduction

In this page you can find the example usage for java.util.concurrent CompletionException CompletionException.

Prototype

public CompletionException(Throwable cause) 

Source Link

Document

Constructs a CompletionException with the specified cause.

Usage

From source file:org.springframework.aop.interceptor.AsyncExecutionAspectSupport.java

/**
 * Delegate for actually executing the given task with the chosen executor.
 * @param task the task to execute/* w  w w .  j  av a  2s  .c o  m*/
 * @param executor the chosen executor
 * @param returnType the declared return type (potentially a {@link Future} variant)
 * @return the execution result (potentially a corresponding {@link Future} handle)
 */
@Nullable
protected Object doSubmit(Callable<Object> task, AsyncTaskExecutor executor, Class<?> returnType) {
    if (CompletableFuture.class.isAssignableFrom(returnType)) {
        return CompletableFuture.supplyAsync(() -> {
            try {
                return task.call();
            } catch (Throwable ex) {
                throw new CompletionException(ex);
            }
        }, executor);
    } else if (ListenableFuture.class.isAssignableFrom(returnType)) {
        return ((AsyncListenableTaskExecutor) executor).submitListenable(task);
    } else if (Future.class.isAssignableFrom(returnType)) {
        return executor.submit(task);
    } else {
        executor.submit(task);
        return null;
    }
}