Top Description Fields Constructors Methods
org.springframework.core.task.support

public Class TaskExecutorAdapter

extends Object
implements AsyncListenableTaskExecutor
Class Inheritance
All Implemented Interfaces
org.springframework.core.task.AsyncListenableTaskExecutor, org.springframework.core.task.AsyncTaskExecutor, org.springframework.core.task.TaskExecutor, java.util.concurrent.Executor
Annotations
@SuppressWarnings:deprecation
Imports
java.util.concurrent.Callable, .Executor, .ExecutorService, .Future, .FutureTask, .RejectedExecutionException, org.springframework.core.task.AsyncListenableTaskExecutor, .TaskDecorator, .TaskRejectedException, org.springframework.lang.Nullable, org.springframework.util.Assert, org.springframework.util.concurrent.ListenableFuture, .ListenableFutureTask

References Deprecated

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

See corresponding docs for further information.

Adapter that takes a JDK 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.
Author
Juergen Hoeller
Since
3.0
See Also
java.util.concurrent.Executor, java.util.concurrent.ExecutorService, java.util.concurrent.Executors

Field Summary

Modifier and TypeField and Description
private final Executor
private TaskDecorator

Constructor Summary

AccessConstructor and Description
public
TaskExecutorAdapter(Executor
the JDK concurrent executor to delegate to
concurrentExecutor
)

Create a new TaskExecutorAdapter, using the given JDK concurrent executor.

Method Summary

Modifier and TypeMethod and Description
protected void
doExecute(Executor
the underlying JDK concurrent executor to delegate to
concurrentExecutor
,
TaskDecorator
the specified decorator to be applied, if any
taskDecorator
,
Runnable
the runnable to execute
runnable
)

Actually execute the given Runnable (which may be a user-supplied task or a wrapper around a user-supplied task) with the given executor.

public void
execute(Runnable
the Runnable to execute (never null)
task
)

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

Delegates to the specified JDK concurrent executor.

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

concurrentExecutorback to summary
private final Executor concurrentExecutor
taskDecoratorback to summary
private TaskDecorator taskDecorator
Annotations
@Nullable

Constructor Detail

TaskExecutorAdapterback to summary
public TaskExecutorAdapter(Executor concurrentExecutor)

Create a new TaskExecutorAdapter, using the given JDK concurrent executor.

Parameters
concurrentExecutor:Executor

the JDK concurrent executor to delegate to

Method Detail

doExecuteback to summary
protected void doExecute(Executor concurrentExecutor, TaskDecorator taskDecorator, Runnable runnable) throws RejectedExecutionException

Actually execute the given Runnable (which may be a user-supplied task or a wrapper around a user-supplied task) with the given executor.

Parameters
concurrentExecutor:Executor

the underlying JDK concurrent executor to delegate to

taskDecorator:TaskDecorator

the specified decorator to be applied, if any

runnable:Runnable

the runnable to execute

Exceptions
RejectedExecutionException:
if the given runnable cannot be accepted
Since
4.3
executeback to summary
public void execute(Runnable task)

Implements org.springframework.core.task.TaskExecutor.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
See Also
java.util.concurrent.Executor#execute(Runnable)
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