Top Description Constructors Methods
org.springframework.util.concurrent

public abstract Class FutureUtils

extends Object
Class Inheritance
Imports
java.util.concurrent.Callable, .CompletableFuture, .CompletionException, .Executor, .ForkJoinPool, java.util.function.Supplier, org.springframework.util.Assert

Convenience utilities for working with java.util.concurrent.Future and implementations.
Author
Arjen Poutsma
Since
6.0

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static <T> CompletableFuture<T>

Returns:

the new CompletableFuture
callAsync
(Callable<T>
a function that returns the value to be used, or throws an exception
callable
)

Return a new CompletableFuture that is asynchronously completed by a task running in the ForkJoinPool#commonPool() with the value obtained by calling the given Callable.

public static <T> CompletableFuture<T>

Returns:

the new CompletableFuture
callAsync
(Callable<T>
a function that returns the value to be used, or throws an exception
callable
,
Executor
the executor to use for asynchronous execution
executor
)

Return a new CompletableFuture that is asynchronously completed by a task running in the given executor with the value obtained by calling the given Callable.

private static <T> Supplier<T>
toSupplier(Callable<T> callable, CompletableFuture<T> result)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

FutureUtilsback to summary
public FutureUtils()

Method Detail

callAsyncback to summary
public static <T> CompletableFuture<T> callAsync(Callable<T> callable)

Return a new CompletableFuture that is asynchronously completed by a task running in the ForkJoinPool#commonPool() with the value obtained by calling the given Callable.

Parameters
callable:Callable<T>

a function that returns the value to be used, or throws an exception

Returns:CompletableFuture<T>

the new CompletableFuture

See Also
CompletableFuture#supplyAsync(Supplier)
callAsyncback to summary
public static <T> CompletableFuture<T> callAsync(Callable<T> callable, Executor executor)

Return a new CompletableFuture that is asynchronously completed by a task running in the given executor with the value obtained by calling the given Callable.

Parameters
callable:Callable<T>

a function that returns the value to be used, or throws an exception

executor:Executor

the executor to use for asynchronous execution

Returns:CompletableFuture<T>

the new CompletableFuture

See Also
CompletableFuture#supplyAsync(Supplier, Executor)
toSupplierback to summary
private static <T> Supplier<T> toSupplier(Callable<T> callable, CompletableFuture<T> result)