Top Description Inners Fields Constructors Methods
org.springframework.scheduling.concurrent

public Class ConcurrentTaskExecutor

extends Object
implements AsyncListenableTaskExecutor, SchedulingTaskExecutor
Class Inheritance
All Implemented Interfaces
org.springframework.scheduling.SchedulingTaskExecutor, org.springframework.core.task.AsyncTaskExecutor, org.springframework.core.task.TaskExecutor, java.util.concurrent.Executor, org.springframework.core.task.AsyncListenableTaskExecutor
Known Direct Subclasses
org.springframework.scheduling.concurrent.ConcurrentTaskScheduler, org.springframework.scheduling.concurrent.DefaultManagedTaskExecutor
Annotations
@SuppressWarnings:deprecation
Imports
java.util.HashMap, .Map, java.util.concurrent.Callable, .Executor, .Executors, .Future, jakarta.enterprise.concurrent.ManagedExecutors, .ManagedTask, org.springframework.core.task.AsyncListenableTaskExecutor, .TaskDecorator, org.springframework.core.task.support.TaskExecutorAdapter, org.springframework.lang.Nullable, org.springframework.scheduling.SchedulingAwareRunnable, .SchedulingTaskExecutor, org.springframework.util.ClassUtils, org.springframework.util.concurrent.ListenableFuture

References Deprecated

AsyncListenableTaskExecutor is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Adapter that takes a java.util.concurrent.Executor and exposes a Spring org.springframework.core.task.TaskExecutor for it. Also detects an extended java.util.concurrent.ExecutorService, adapting the org.springframework.core.task.AsyncTaskExecutor interface accordingly.

Autodetects a JSR-236 jakarta.enterprise.concurrent.ManagedExecutorService in order to expose jakarta.enterprise.concurrent.ManagedTask adapters for it, exposing a long-running hint based on SchedulingAwareRunnable and an identity name based on the given Runnable/Callable's toString(). For JSR-236 style lookup in a Jakarta EE environment, consider using DefaultManagedTaskExecutor.

Note that there is a pre-built ThreadPoolTaskExecutor that allows for defining a java.util.concurrent.ThreadPoolExecutor in bean style, exposing it as a Spring org.springframework.core.task.TaskExecutor directly. This is a convenient alternative to a raw ThreadPoolExecutor definition with a separate definition of the present adapter class.

Author
Juergen Hoeller
Since
2.0
See Also
java.util.concurrent.Executor, java.util.concurrent.ExecutorService, java.util.concurrent.ThreadPoolExecutor, java.util.concurrent.Executors, DefaultManagedTaskExecutor, ThreadPoolTaskExecutor

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class
ConcurrentTaskExecutor.ManagedTaskBuilder

Delegate that wraps a given Runnable/Callable with a JSR-236 ManagedTask, exposing a long-running hint based on SchedulingAwareRunnable and a given identity name.

private static class
ConcurrentTaskExecutor.ManagedTaskExecutorAdapter

References Deprecated TaskExecutorAdapter is deprecated or references (maybe indirectly) at least one deprecated element.
TaskExecutorAdapter subclass that wraps all provided Runnables and Callables with a JSR-236 ManagedTask, exposing a long-running hint based on SchedulingAwareRunnable and an identity name based on the task's toString() representation.

Field Summary

Modifier and TypeField and Description
private TaskExecutorAdapter
adaptedExecutor

References Deprecated TaskExecutorAdapter is deprecated or references (maybe indirectly) at least one deprecated element.
private Executor
private static Class<?>
private static final Executor
private TaskDecorator

Constructor Summary

AccessConstructor and Description
public
ConcurrentTaskExecutor()
Deprecated since 6.1. in favor of ConcurrentTaskExecutor(Executor) with an externally provided Executor

Create a new ConcurrentTaskExecutor, using a single thread executor as default.

public
ConcurrentTaskExecutor(Executor executor)

Create a new ConcurrentTaskExecutor, using the given java.util.concurrent.Executor.

Method Summary

Modifier and TypeMethod and Description
public void
execute(Runnable
the Runnable to execute (never null)
task
)

Implements org.springframework.core.task.TaskExecutor.execute.

Execute the given task.

public 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
)

Overrides default org.springframework.core.task.AsyncTaskExecutor.execute.

Deprecated

Execute the given task.

private TaskExecutorAdapter
getAdaptedExecutor(Executor concurrentExecutor)
References Deprecated TaskExecutorAdapter is deprecated or references (maybe indirectly) at least one deprecated element.

public final Executor
getConcurrentExecutor()

Return the java.util.concurrent.Executor that this adapter delegates to.

public final void
setConcurrentExecutor(Executor executor)

Specify the java.util.concurrent.Executor to delegate to.

public final void
setTaskDecorator(TaskDecorator taskDecorator)

Specify a custom TaskDecorator to be applied to any Runnable about to be executed.

public Future<?>
submit(Runnable
the Runnable to execute (never null)
task
)

Overrides default org.springframework.core.task.AsyncTaskExecutor.submit.

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

public <T> Future<T>
submit(Callable<T>
the Callable to execute (never null)
task
)

Overrides default org.springframework.core.task.AsyncTaskExecutor.submit.

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

public ListenableFuture<?>
submitListenable(Runnable
the Runnable to execute (never null)
task
)

Implements org.springframework.core.task.AsyncListenableTaskExecutor.submitListenable.

References Deprecated ListenableFuture is deprecated or references (maybe indirectly) at least one deprecated element.

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

public <T> ListenableFuture<T>
submitListenable(Callable<T>
the Callable to execute (never null)
task
)

Implements org.springframework.core.task.AsyncListenableTaskExecutor.submitListenable.

References Deprecated ListenableFuture is deprecated or references (maybe indirectly) at least one deprecated element.

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

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

adaptedExecutorback to summary
private TaskExecutorAdapter adaptedExecutor

References Deprecated

TaskExecutorAdapter is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

concurrentExecutorback to summary
private Executor concurrentExecutor
managedExecutorServiceClassback to summary
private static Class<?> managedExecutorServiceClass
Annotations
@Nullable
STUB_EXECUTORback to summary
private static final Executor STUB_EXECUTOR
taskDecoratorback to summary
private TaskDecorator taskDecorator
Annotations
@Nullable

Constructor Detail

ConcurrentTaskExecutorback to summary
public ConcurrentTaskExecutor()

Deprecated

since 6.1.

in favor of ConcurrentTaskExecutor(Executor) with an externally provided Executor

Create a new ConcurrentTaskExecutor, using a single thread executor as default.

Annotations
@Deprecated
since:6.1
See Also
java.util.concurrent.Executors#newSingleThreadExecutor()
ConcurrentTaskExecutorback to summary
public ConcurrentTaskExecutor(Executor executor)

Create a new ConcurrentTaskExecutor, using the given java.util.concurrent.Executor.

Autodetects a JSR-236 jakarta.enterprise.concurrent.ManagedExecutorService in order to expose jakarta.enterprise.concurrent.ManagedTask adapters for it.

Parameters
executor:Executor

the java.util.concurrent.Executor to delegate to

Method Detail

executeback to summary
public void execute(Runnable task)

Implements org.springframework.core.task.TaskExecutor.execute.

Doc from org.springframework.core.task.TaskExecutor.execute.

Execute the given task.

The call might return immediately if the implementation uses an asynchronous execution strategy, or might block in the case of synchronous execution.

Parameters
task:Runnable

the Runnable to execute (never null)

Annotations
@Override
executeback to summary
public void execute(Runnable task, long startTimeout)

Overrides default org.springframework.core.task.AsyncTaskExecutor.execute.

Doc from org.springframework.core.task.AsyncTaskExecutor.execute.

Deprecated

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
@Override
getAdaptedExecutorback to summary
private TaskExecutorAdapter getAdaptedExecutor(Executor concurrentExecutor)

References Deprecated

TaskExecutorAdapter is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

getConcurrentExecutorback to summary
public final Executor getConcurrentExecutor()

Return the java.util.concurrent.Executor that this adapter delegates to.

setConcurrentExecutorback to summary
public final void setConcurrentExecutor(Executor executor)

Specify the java.util.concurrent.Executor to delegate to.

Autodetects a JSR-236 jakarta.enterprise.concurrent.ManagedExecutorService in order to expose jakarta.enterprise.concurrent.ManagedTask adapters for it.

setTaskDecoratorback to summary
public final void setTaskDecorator(TaskDecorator taskDecorator)

Specify a custom TaskDecorator to be applied to any Runnable about to be executed.

Note that such a decorator is not necessarily being applied to the user-supplied Runnable/Callable but rather to the actual execution callback (which may be a wrapper around the user-supplied task).

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 TaskDecorator implementations is limited to plain Runnable execution via execute calls. In case of #submit calls, the exposed Runnable will be a FutureTask which does not propagate any exceptions; you might have to cast it and call Future#get to evaluate exceptions.

Since
4.3
submitback to summary
public Future<?> submit(Runnable task)

Overrides default org.springframework.core.task.AsyncTaskExecutor.submit.

Doc from org.springframework.core.task.AsyncTaskExecutor.submit.

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

Annotations
@Override
submitback to summary
public <T> Future<T> submit(Callable<T> task)

Overrides default org.springframework.core.task.AsyncTaskExecutor.submit.

Doc from org.springframework.core.task.AsyncTaskExecutor.submit.

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

Annotations
@Override
submitListenableback to summary
public ListenableFuture<?> submitListenable(Runnable task)

Implements org.springframework.core.task.AsyncListenableTaskExecutor.submitListenable.

Doc from org.springframework.core.task.AsyncListenableTaskExecutor.submitListenable.

References Deprecated

ListenableFuture is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

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

Parameters
task:Runnable

the Runnable to execute (never null)

Returns:ListenableFuture<?>

a ListenableFuture representing pending completion of the task

Annotations
@Override
submitListenableback to summary
public <T> ListenableFuture<T> submitListenable(Callable<T> task)

Implements org.springframework.core.task.AsyncListenableTaskExecutor.submitListenable.

Doc from org.springframework.core.task.AsyncListenableTaskExecutor.submitListenable.

References Deprecated

ListenableFuture is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

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

Parameters
task:Callable<T>

the Callable to execute (never null)

Returns:ListenableFuture<T>

a ListenableFuture representing pending completion of the task

Annotations
@Override
org.springframework.scheduling.concurrent back to summary

protected Class ConcurrentTaskExecutor.ManagedTaskBuilder

extends Object
Class Inheritance
  • java.lang.Object
  • org.springframework.scheduling.concurrent.ConcurrentTaskExecutor.ManagedTaskBuilder

Delegate that wraps a given Runnable/Callable with a JSR-236 ManagedTask, exposing a long-running hint based on SchedulingAwareRunnable and a given identity name.

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public static Runnable
buildManagedTask(Runnable task, String identityName)

public static <T> Callable<T>
buildManagedTask(Callable<T> task, String identityName)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ManagedTaskBuilderback to summary
protected ManagedTaskBuilder()

Method Detail

buildManagedTaskback to summary
public static Runnable buildManagedTask(Runnable task, String identityName)
buildManagedTaskback to summary
public static <T> Callable<T> buildManagedTask(Callable<T> task, String identityName)
org.springframework.scheduling.concurrent back to summary

private Class ConcurrentTaskExecutor.ManagedTaskExecutorAdapter

extends TaskExecutorAdapter
Class Inheritance

References Deprecated

TaskExecutorAdapter is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

TaskExecutorAdapter subclass that wraps all provided Runnables and Callables with a JSR-236 ManagedTask, exposing a long-running hint based on SchedulingAwareRunnable and an identity name based on the task's toString() representation.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
execute(Runnable
the Runnable to execute (never null)
task
)

Overrides org.springframework.core.task.support.TaskExecutorAdapter.execute.

Implements org.springframework.core.task.TaskExecutor.execute.

Delegates to the specified JDK concurrent executor.

public Future<?>
submit(Runnable
the Runnable to execute (never null)
task
)

Overrides org.springframework.core.task.support.TaskExecutorAdapter.submit.

Overrides default org.springframework.core.task.AsyncTaskExecutor.submit.

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

public <T> Future<T>
submit(Callable<T>
the Callable to execute (never null)
task
)

Overrides org.springframework.core.task.support.TaskExecutorAdapter.submit.

Overrides default org.springframework.core.task.AsyncTaskExecutor.submit.

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

public ListenableFuture<?>
submitListenable(Runnable
the Runnable to execute (never null)
task
)

Overrides org.springframework.core.task.support.TaskExecutorAdapter.submitListenable.

Implements org.springframework.core.task.AsyncListenableTaskExecutor.submitListenable.

References Deprecated ListenableFuture is deprecated or references (maybe indirectly) at least one deprecated element.

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

public <T> ListenableFuture<T>
submitListenable(Callable<T>
the Callable to execute (never null)
task
)

Overrides org.springframework.core.task.support.TaskExecutorAdapter.submitListenable.

Implements org.springframework.core.task.AsyncListenableTaskExecutor.submitListenable.

References Deprecated ListenableFuture is deprecated or references (maybe indirectly) at least one deprecated element.

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

Inherited from org.springframework.core.task.support.TaskExecutorAdapter:
doExecutesetTaskDecorator

Constructor Detail

ManagedTaskExecutorAdapterback to summary
public ManagedTaskExecutorAdapter(Executor concurrentExecutor)

Method Detail

executeback to summary
public void execute(Runnable task)

Overrides org.springframework.core.task.support.TaskExecutorAdapter.execute.

Implements org.springframework.core.task.TaskExecutor.execute.

Doc from org.springframework.core.task.support.TaskExecutorAdapter.execute.

Delegates to the specified JDK concurrent executor.

Parameters
task:Runnable

Doc from org.springframework.core.task.TaskExecutor.execute.

the Runnable to execute (never null)

Annotations
@Override
submitback to summary
public Future<?> submit(Runnable task)

Overrides org.springframework.core.task.support.TaskExecutorAdapter.submit.

Overrides default org.springframework.core.task.AsyncTaskExecutor.submit.

Doc from org.springframework.core.task.AsyncTaskExecutor.submit.

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

Annotations
@Override
submitback to summary
public <T> Future<T> submit(Callable<T> task)

Overrides org.springframework.core.task.support.TaskExecutorAdapter.submit.

Overrides default org.springframework.core.task.AsyncTaskExecutor.submit.

Doc from org.springframework.core.task.AsyncTaskExecutor.submit.

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

Annotations
@Override
submitListenableback to summary
public ListenableFuture<?> submitListenable(Runnable task)

Overrides org.springframework.core.task.support.TaskExecutorAdapter.submitListenable.

Implements org.springframework.core.task.AsyncListenableTaskExecutor.submitListenable.

Doc from org.springframework.core.task.AsyncListenableTaskExecutor.submitListenable.

References Deprecated

ListenableFuture is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

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

Parameters
task:Runnable

the Runnable to execute (never null)

Returns:ListenableFuture<?>

a ListenableFuture representing pending completion of the task

Annotations
@Override
submitListenableback to summary
public <T> ListenableFuture<T> submitListenable(Callable<T> task)

Overrides org.springframework.core.task.support.TaskExecutorAdapter.submitListenable.

Implements org.springframework.core.task.AsyncListenableTaskExecutor.submitListenable.

Doc from org.springframework.core.task.AsyncListenableTaskExecutor.submitListenable.

References Deprecated

ListenableFuture is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

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

Parameters
task:Callable<T>

the Callable to execute (never null)

Returns:ListenableFuture<T>

a ListenableFuture representing pending completion of the task

Annotations
@Override