Package org.springframework.core.task

# Interface AsyncTaskExecutor

All Superinterfaces:
  `Executor`, `TaskExecutor`

All Known Subinterfaces:
  `AsyncListenableTaskExecutor`

All Known Implementing Classes:
  `SimpleAsyncTaskExecutor`, `TaskExecutorAdapter`, `VirtualThreadTaskExecutor`

public interface AsyncTaskExecutor extends TaskExecutor
Extended interface for asynchronous `TaskExecutor` implementations, offering support for `Future`/`CompletableFuture` handles.

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

Since:
  2.0.3
Author:
  Juergen Hoeller
See Also:
  - `SimpleAsyncTaskExecutor`
  - `org.springframework.scheduling.SchedulingTaskExecutor`
  - `Callable`
  - `Executors`

## Field Summary

Fields
Modifier and Type
Field
Description
`static final long`
`TIMEOUT_IMMEDIATE`
Deprecated.
as of 5.3.16 along with `execute(Runnable, long)`
`static final long`
`TIMEOUT_INDEFINITE`
Deprecated.
as of 5.3.16 along with `execute(Runnable, long)`

## Method Summary

Modifier and Type
Method
Description
`default void`
`execute(Runnable task, long startTimeout)`
Deprecated.
as of 5.3.16 since the common executors do not support start timeouts
`default Future<?>`
`submit(Runnable task)`
Submit a Runnable task for execution, receiving a Future representing that task.
`default <T> Future<T>`
`submit(Callable<T> task)`
Submit a Callable task for execution, receiving a Future representing that task.
`default CompletableFuture<Void>`
`submitCompletable(Runnable task)`
Submit a `Runnable` task for execution, receiving a `CompletableFuture` representing that task.
`default <T> CompletableFuture<T>`
`submitCompletable(Callable<T> task)`
Submit a `Callable` task for execution, receiving a `CompletableFuture` representing that task.

### Methods inherited from interface org.springframework.core.task.TaskExecutor

`execute`

## Field Details

### TIMEOUT_IMMEDIATE

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

See Also:
  - Constant Field Values

### TIMEOUT_INDEFINITE

@Deprecated static final long TIMEOUT_INDEFINITE
Deprecated.
as of 5.3.16 along with `execute(Runnable, long)`
Constant that indicates no time limit.

See Also:
  - Constant Field Values

## Method Details

### execute

@Deprecated 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 `TaskExecutor.execute(Runnable)`, ignoring the timeout completely.

Parameters:
  `task` - the `Runnable` to execute (never `null`)
  `startTimeout` - 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 `TaskExecutor.execute(Runnable)`).
Throws:
  `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:
  - `TaskExecutor.execute(Runnable)`

### submit

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 `TaskExecutor.execute(Runnable)`.

Parameters:
  `task` - the `Runnable` to execute (never `null`)
Returns:
  a Future representing pending completion of the task
Throws:
  `TaskRejectedException` - if the given task was not accepted
Since:
  3.0

### submit

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 `TaskExecutor.execute(Runnable)`.

Parameters:
  `task` - the `Callable` to execute (never `null`)
Returns:
  a Future representing pending completion of the task
Throws:
  `TaskRejectedException` - if the given task was not accepted
Since:
  3.0

### submitCompletable

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` - the `Runnable` to execute (never `null`)
Returns:
  a `CompletableFuture` representing pending completion of the task
Throws:
  `TaskRejectedException` - if the given task was not accepted
Since:
  6.0

### submitCompletable

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` - the `Callable` to execute (never `null`)
Returns:
  a `CompletableFuture` representing pending completion of the task
Throws:
  `TaskRejectedException` - if the given task was not accepted
Since:
  6.0