public final class Futures extends Object
public 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–2016. All rights reserved.