References Deprecated
AsyncListenableTaskExecutor is deprecated or references (maybe indirectly) at least one deprecated element.
See corresponding docs for further information.
TaskExecutor implementation that fires up a new Thread for each task,
executing it asynchronously. Provides a virtual thread option on JDK 21.
Supports a graceful shutdown through setTaskTerminationTimeout,
at the expense of task tracking overhead per execution thread at runtime.
Supports limiting concurrent threads through setConcurrencyLimit.
By default, the number of concurrent task executions is unlimited.
NOTE: This implementation does not reuse threads! Consider a
thread-pooling TaskExecutor implementation instead, in particular for
executing a large number of short-lived tasks. Alternatively, on JDK 21,
consider setting setVirtualThreads to true.
setVirtualThreads, setTaskTerminationTimeout, setConcurrencyLimit, org.springframework.scheduling.concurrent.SimpleAsyncTaskScheduler , org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
| Modifier and Type | Class and Description |
|---|---|
| private static class | SimpleAsyncTaskExecutor.
Subclass of the general ConcurrencyThrottleSupport class,
making |
| private class | SimpleAsyncTaskExecutor.
Decorates a target task with active thread tracking and concurrency throttle management, if necessary. |
| Modifier and Type | Field and Description |
|---|---|
| private volatile boolean | |
| private Set | |
| private final SimpleAsyncTaskExecutor. | concurrencyThrottle
Internal concurrency throttle used by this executor. |
| public static final int | NO_CONCURRENCY
Switch concurrency 'off': that is, don't allow any concurrent invocations. |
| private TaskDecorator | |
| private long | |
| private ThreadFactory | |
| public static final int | UNBOUNDED_CONCURRENCY
Permit any number of concurrent invocations: that is, don't throttle concurrency. |
| private VirtualThreadDelegate |
| Access | Constructor and Description |
|---|---|
| public | |
| public | SimpleAsyncTaskExecutor(String
the prefix to use for the names of newly created threads threadNamePrefix)Create a new SimpleAsyncTaskExecutor with the given thread name prefix. |
| public | SimpleAsyncTaskExecutor(ThreadFactory
the factory to use for creating new Threads threadFactory)Create a new SimpleAsyncTaskExecutor with the given external thread factory. |
| Modifier and Type | Method and Description |
|---|---|
| public void | close()
Implements java. This close methods tracks the termination of active threads if a concrete
|
| protected void | |
| public void | execute(Runnable
the task)Runnable to execute (never null)Implements org. Executes the given task, within a concurrency throttle if configured (through the superclass's settings). |
| public void | execute(Runnable
the task, long Runnable to execute (never null)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 startTimeout)TIMEOUT_IMMEDIATE
or TIMEOUT_INDEFINITE (the default as used by execute(Runnable)).Overrides default org.
Deprecated
Executes the given task, within a concurrency throttle if configured (through the superclass's settings). |
| public final int | |
| public final ThreadFactory | |
| public boolean | isActive()
Return whether this executor is still active, i.e. not closed yet, and therefore accepts further task submissions. |
| public final boolean | Returns: true if the concurrency limit for this instance is activeReturn whether the concurrency throttle is currently active. |
| protected Thread | |
| public void | setConcurrencyLimit(int concurrencyLimit)
Set the maximum number of parallel task executions allowed. |
| public void | setTaskDecorator(TaskDecorator taskDecorator)
Specify a custom |
| public void | setTaskTerminationTimeout(long
the timeout in milliseconds timeout)Specify a timeout (in milliseconds) for task termination when closing this executor. |
| public void | setThreadFactory(ThreadFactory threadFactory)
Specify an external factory to use for creating new Threads, instead of relying on the local properties of this executor. |
| public void | |
| public Future | submit(Runnable
the task)Runnable to execute (never null)Overrides default org. Submit a Runnable task for execution, receiving a Future representing that task. |
| public <T> Future | submit(Callable<T>
the task)Callable to execute (never null)Overrides default org. Submit a Callable task for execution, receiving a Future representing that task. |
| public ListenableFuture | submitListenable(Runnable
the task)Runnable to execute (never null)Implements org.
References Deprecated
ListenableFuture is deprecated or references (maybe indirectly) at least one deprecated element.
Submit a |
| public <T> ListenableFuture | submitListenable(Callable<T>
the task)Callable to execute (never null)Implements org.
References Deprecated
ListenableFuture is deprecated or references (maybe indirectly) at least one deprecated element.
Submit a |
| active | back to summary |
|---|---|
| private volatile boolean active | |
| activeThreads | back to summary |
|---|---|
| private Set<Thread> activeThreads
| |
| concurrencyThrottle | back to summary |
|---|---|
| private final SimpleAsyncTaskExecutor. Internal concurrency throttle used by this executor. | |
| NO_CONCURRENCY | back to summary |
|---|---|
| public static final int NO_CONCURRENCY Switch concurrency 'off': that is, don't allow any concurrent invocations. | |
| taskDecorator | back to summary |
|---|---|
| private TaskDecorator taskDecorator
| |
| taskTerminationTimeout | back to summary |
|---|---|
| private long taskTerminationTimeout | |
| threadFactory | back to summary |
|---|---|
| private ThreadFactory threadFactory
| |
| UNBOUNDED_CONCURRENCY | back to summary |
|---|---|
| public static final int UNBOUNDED_CONCURRENCY Permit any number of concurrent invocations: that is, don't throttle concurrency. | |
| virtualThreadDelegate | back to summary |
|---|---|
| private VirtualThreadDelegate virtualThreadDelegate
| |
| SimpleAsyncTaskExecutor | back to summary |
|---|---|
| public SimpleAsyncTaskExecutor() Create a new SimpleAsyncTaskExecutor with default thread name prefix. | |
| SimpleAsyncTaskExecutor | back to summary |
|---|---|
| public SimpleAsyncTaskExecutor(String threadNamePrefix) Create a new SimpleAsyncTaskExecutor with the given thread name prefix.
| |
| SimpleAsyncTaskExecutor | back to summary |
|---|---|
| public SimpleAsyncTaskExecutor(ThreadFactory threadFactory) Create a new SimpleAsyncTaskExecutor with the given external thread factory.
| |
| close | back to summary |
|---|---|
| public void close() Implements java. This close methods tracks the termination of active threads if a concrete
| |
| doExecute | back to summary |
|---|---|
| protected void doExecute(Runnable task) Template method for the actual execution of a task. The default implementation creates a new Thread and starts it.
| |
| execute | back to summary |
|---|---|
| public void execute(Runnable task) Implements org. Executes the given task, within a concurrency throttle if configured (through the superclass's settings).
| |
| execute | back to summary |
|---|---|
| public void execute(Runnable task, long startTimeout) Overrides default org. Deprecated
Executes the given task, within a concurrency throttle if configured (through the superclass's settings). Executes urgent tasks (with 'immediate' timeout) directly, bypassing the concurrency throttle (if active). All other tasks are subject to throttling.
| |
| getConcurrencyLimit | back to summary |
|---|---|
| public final int getConcurrencyLimit() Return the maximum number of parallel task executions allowed. | |
| getThreadFactory | back to summary |
|---|---|
| public final ThreadFactory getThreadFactory() Return the external factory to use for creating new Threads, if any.
| |
| isActive | back to summary |
|---|---|
| public boolean isActive() Return whether this executor is still active, i.e. not closed yet, and therefore accepts further task submissions. Otherwise, it is either in the task termination phase or entirely shut down already.
| |
| isThrottleActive | back to summary |
|---|---|
| public final boolean isThrottleActive() Return whether the concurrency throttle is currently active.
| |
| newThread | back to summary |
|---|---|
| protected Thread newThread(Runnable task) Create a new Thread for the given task.
| |
| setConcurrencyLimit | back to summary |
|---|---|
| public void setConcurrencyLimit(int concurrencyLimit) Set the maximum number of parallel task executions allowed. The default of -1 indicates no concurrency limit at all. This is the equivalent of a maximum pool size in a thread pool, preventing temporary overload of the thread management system. | |
| setTaskDecorator | back to summary |
|---|---|
| public void setTaskDecorator(TaskDecorator taskDecorator) Specify a custom Note that such a decorator is not necessarily being applied to the
user-supplied The primary use case is to set some execution context around the task's invocation, or to provide some monitoring/statistics for task execution. Note Exception handling in
| |
| setTaskTerminationTimeout | back to summary |
|---|---|
| public void setTaskTerminationTimeout(long timeout) Specify a timeout (in milliseconds) for task termination when closing this executor. The default is 0, not waiting for task termination at all. Note that a concrete >0 timeout specified here will lead to the wrapping of every submitted task into a task-tracking runnable which involves considerable overhead in case of a high number of tasks. However, for a modest level of submissions with longer-running tasks, this is feasible in order to arrive at a graceful shutdown. Note that
| |
| setThreadFactory | back to summary |
|---|---|
| public void setThreadFactory(ThreadFactory threadFactory) Specify an external factory to use for creating new Threads, instead of relying on the local properties of this executor. You may specify an inner ThreadFactory bean or also a ThreadFactory reference obtained from JNDI (on a Jakarta EE server) or some other lookup mechanism.
| |
| setVirtualThreads | back to summary |
|---|---|
| public void setVirtualThreads(boolean virtual) Switch this executor to virtual threads. Requires Java 21 or higher. The default is
| |
| submit | back to summary |
|---|---|
| public Future Overrides default org. Doc from org. Submit a Runnable task for execution, receiving a Future representing that task.
The Future will return a As of 6.1, this method comes with a default implementation that delegates
to
| |
| submit | back to summary |
|---|---|
| public <T> Future Overrides default org. Doc from org. 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
| |
| submitListenable | back to summary |
|---|---|
| public ListenableFuture Implements org. Doc from org. References Deprecated
See corresponding docs for further information. Submit a
| |
| submitListenable | back to summary |
|---|---|
| public <T> ListenableFuture Implements org. Doc from org. References Deprecated
See corresponding docs for further information. Submit a
| |
beforeAccess() and afterAccess()
visible to the surrounding class.
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| protected void | afterAccess()
Overrides org. To be invoked after the main execution logic of concrete subclasses. |
| protected void | beforeAccess()
Overrides org. To be invoked before the main execution logic of concrete subclasses. |
| ConcurrencyThrottleAdapter | back to summary |
|---|---|
| private ConcurrencyThrottleAdapter() | |
| afterAccess | back to summary |
|---|---|
| protected void afterAccess() Overrides org. Doc from org. To be invoked after the main execution logic of concrete subclasses.
| |
| beforeAccess | back to summary |
|---|---|
| protected void beforeAccess() Overrides org. Doc from org. To be invoked before the main execution logic of concrete subclasses. This implementation applies the concurrency throttle.
| |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void |
| task | back to summary |
|---|---|
| private final Runnable task | |
| TaskTrackingRunnable | back to summary |
|---|---|
| public TaskTrackingRunnable(Runnable task) | |
| run | back to summary |
|---|---|
| public void run() Implements java. Doc from java. Runs this operation.
| |