public final class Futures extends Object
| Modifier and Type | Method and Description |
|---|---|
static <T> Future<T> |
delegate(T obj)
|
static <T> CompletableFuture<T> |
delegateCompletable(T obj)
Returns a dummy
CompletableFuture object to be used to return a value in
methods that are annotated with Async. |
public static <T> CompletableFuture<T> delegateCompletable(T obj)
CompletableFuture object to be used to return a value in
methods that are annotated with Async. Sample usage:
@Async
public CompletableFuture<Integer> calculateAsync() {
final Integer result = doHeavyCalculation();
return Futures.delegateCompletable(result);
}
You should not use the returned dummy object for any other purpose than returning
it from a method which is annotated with Async.
API Note
The MethodInterceptor which handles the asynchronous invocations will
extract the wrapped Object from this dummy CompletableFuture and create an actual
CompletableFuture which is backed by the ExecutorService in place. Thus,
the dummy Object created here will never leave the context of the method it is
created in (if you do not manually leak it to the outside).
T - Type of the Object to return.obj - The Object to return.Asyncpublic static <T> Future<T> delegate(T obj)
Future object to be used to return a value in methods that
are annotated with Async. Sample usage:
@Async
public Future<Integer> calculateAsync() {
final Integer result = doHeavyCalculation();
return Futures.delegate(result);
}
You should not use the returned dummy object for any other purpose than returning
it from a method which is annotated with Async.
API Note
The MethodInterceptor which handles the asynchronous invocations will
extract the wrapped Object from this dummy Future and create an actual Future
object by submitting the method invocation to an ExecutorService. Thus, the
dummy Object created here will never leave the context of the method it is created
in (if you do not manually leak it to the outside).
T - Type of the Object to return.obj - The Object to return.AsyncCopyright © 2014–2018. All rights reserved.