Top Description Fields Methods
org.springframework.core.task

public Interface AsyncTaskExecutor

extends TaskExecutor
Known Direct Subinterfaces
org.springframework.core.task.AsyncListenableTaskExecutor
Known Direct Implementers
org.springframework.core.task.VirtualThreadTaskExecutor
Imports
java.util.concurrent.Callable, .CompletableFuture, .Future, .FutureTask, org.springframework.util.concurrent.FutureUtils

Extended interface for asynchronous TaskExecutor implementations, offering support for java.util.concurrent.Callable.

Note

The java.util.concurrent.Executors class includes a set of methods that can convert some other common closure-like objects, for example, java.security.PrivilegedAction to Callable before executing them.

Implementing this interface also indicates that the execute(Runnable) method will not execute its Runnable in the caller's thread but rather asynchronously in some other thread.

Author
Juergen Hoeller
Since
2.0.3
See Also
SimpleAsyncTaskExecutor, org.springframework.scheduling.SchedulingTaskExecutor, java.util.concurrent.Callable, java.util.concurrent.Executors

Field Summary

Modifier and TypeField and Description
public static final long
TIMEOUT_IMMEDIATE

Deprecated as of 5.3.16 along with execute(Runnable, long)
Constant that indicates immediate execution.
public static final long
TIMEOUT_INDEFINITE

Deprecated as of 5.3.16 along with execute(Runnable, long)
Constant that indicates no time limit.

Method Summary

Modifier and TypeMethod and Description
public default void
execute(Runnable
the Runnable to execute (never null)
task
,
long
the time duration (milliseconds) within which the task is supposed to start. This is intended as a hint to the executor, allowing for preferred handling of immediate tasks. Typical values are TIMEOUT_IMMEDIATE or TIMEOUT_INDEFINITE (the default as used by execute(Runnable)).
startTimeout
)
Deprecated as of 5.3.16 since the common executors do not support start timeouts

Execute the given task.

public default Future<?>

Returns:

a Future representing pending completion of the task
submit
(Runnable
the Runnable to execute (never null)
task
)

Submit a Runnable task for execution, receiving a Future representing that task.

public default <T> Future<T>

Returns:

a Future representing pending completion of the task
submit
(Callable<T>
the Callable to execute (never null)
task
)

Submit a Callable task for execution, receiving a Future representing that task.

public default CompletableFuture<Void>

Returns:

a CompletableFuture representing pending completion of the task
submitCompletable
(Runnable
the Runnable to execute (never null)
task
)

Submit a Runnable task for execution, receiving a CompletableFuture representing that task.

public default <T> CompletableFuture<T>

Returns:

a CompletableFuture representing pending completion of the task
submitCompletable
(Callable<T>
the Callable to execute (never null)
task
)

Submit a Callable task for execution, receiving a CompletableFuture representing that task.

Inherited from org.springframework.core.task.TaskExecutor:
execute

Field Detail

TIMEOUT_IMMEDIATEback to summary
public static final long TIMEOUT_IMMEDIATE

Deprecated

as of 5.3.16 along with execute(Runnable, long)

Constant that indicates immediate execution.

Annotations
@Deprecated
TIMEOUT_INDEFINITEback to summary
public static final long TIMEOUT_INDEFINITE

Deprecated

as of 5.3.16 along with execute(Runnable, long)

Constant that indicates no time limit.

Annotations
@Deprecated

Method Detail

executeback to summary
public default void execute(Runnable task, long startTimeout)

Deprecated

as of 5.3.16 since the common executors do not support start timeouts

Execute the given task.

As of 6.1, this method comes with a default implementation that simply delegates to execute(Runnable), ignoring the timeout completely.

Parameters
task:Runnable

the Runnable to execute (never null)

startTimeout:long

the time duration (milliseconds) within which the task is supposed to start. This is intended as a hint to the executor, allowing for preferred handling of immediate tasks. Typical values are TIMEOUT_IMMEDIATE or TIMEOUT_INDEFINITE (the default as used by execute(Runnable)).

Annotations
@Deprecated
Exceptions
TaskTimeoutException:
in case of the task being rejected because of the timeout (i.e. it cannot be started in time)
TaskRejectedException:
if the given task was not accepted
See Also
execute(Runnable)
submitback to summary
public default Future<?> submit(Runnable task)

Submit a Runnable task for execution, receiving a Future representing that task. The Future will return a null result upon completion.

As of 6.1, this method comes with a default implementation that delegates to execute(Runnable).

Parameters
task:Runnable

the Runnable to execute (never null)

Returns:Future<?>

a Future representing pending completion of the task

Exceptions
TaskRejectedException:
if the given task was not accepted
Since
3.0
submitback to summary
public default <T> Future<T> submit(Callable<T> task)

Submit a Callable task for execution, receiving a Future representing that task. The Future will return the Callable's result upon completion.

As of 6.1, this method comes with a default implementation that delegates to execute(Runnable).

Parameters
task:Callable<T>

the Callable to execute (never null)

Returns:Future<T>

a Future representing pending completion of the task

Exceptions
TaskRejectedException:
if the given task was not accepted
Since
3.0
submitCompletableback to summary
public default CompletableFuture<Void> submitCompletable(Runnable task)

Submit a Runnable task for execution, receiving a CompletableFuture representing that task. The Future will return a null result upon completion.

Parameters
task:Runnable

the Runnable to execute (never null)

Returns:CompletableFuture<Void>

a CompletableFuture representing pending completion of the task

Exceptions
TaskRejectedException:
if the given task was not accepted
Since
6.0
submitCompletableback to summary
public default <T> CompletableFuture<T> submitCompletable(Callable<T> task)

Submit a Callable task for execution, receiving a CompletableFuture representing that task. The Future will return the Callable's result upon completion.

Parameters
task:Callable<T>

the Callable to execute (never null)

Returns:CompletableFuture<T>

a CompletableFuture representing pending completion of the task

Exceptions
TaskRejectedException:
if the given task was not accepted
Since
6.0