Class TaskExecutorAdapter
- All Implemented Interfaces:
Executor
,AsyncListenableTaskExecutor
,AsyncTaskExecutor
,TaskExecutor
java.util.concurrent.Executor
and
exposes a Spring TaskExecutor
for it.
Also detects an extended java.util.concurrent.ExecutorService
, adapting
the AsyncTaskExecutor
interface accordingly.- Since:
- 3.0
- Author:
- Juergen Hoeller
- See Also:
-
Field Summary
Fields inherited from interface org.springframework.core.task.AsyncTaskExecutor
TIMEOUT_IMMEDIATE, TIMEOUT_INDEFINITE
-
Constructor Summary
ConstructorDescriptionTaskExecutorAdapter
(Executor concurrentExecutor) Create a new TaskExecutorAdapter, using the given JDK concurrent executor. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
doExecute
(Executor concurrentExecutor, TaskDecorator taskDecorator, Runnable runnable) Actually execute the givenRunnable
(which may be a user-supplied task or a wrapper around a user-supplied task) with the given executor.void
Delegates to the specified JDK concurrent executor.final void
setTaskDecorator
(TaskDecorator taskDecorator) Specify a customTaskDecorator
to be applied to anyRunnable
about to be executed.Future<?>
Submit a Runnable task for execution, receiving a Future representing that task.<T> Future<T>
Submit a Callable task for execution, receiving a Future representing that task.submitListenable
(Runnable task) Submit aRunnable
task for execution, receiving aListenableFuture
representing that task.<T> ListenableFuture<T>
submitListenable
(Callable<T> task) Submit aCallable
task for execution, receiving aListenableFuture
representing that task.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.core.task.AsyncTaskExecutor
execute, submitCompletable, submitCompletable
-
Constructor Details
-
TaskExecutorAdapter
Create a new TaskExecutorAdapter, using the given JDK concurrent executor.- Parameters:
concurrentExecutor
- the JDK concurrent executor to delegate to
-
-
Method Details
-
setTaskDecorator
Specify a customTaskDecorator
to be applied to anyRunnable
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 plainRunnable
execution viaexecute
calls. In case of#submit
calls, the exposedRunnable
will be aFutureTask
which does not propagate any exceptions; you might have to cast it and callFuture#get
to evaluate exceptions.- Since:
- 4.3
-
execute
Delegates to the specified JDK concurrent executor.- Specified by:
execute
in interfaceExecutor
- Specified by:
execute
in interfaceTaskExecutor
- Parameters:
task
- theRunnable
to execute (nevernull
)- See Also:
-
submit
Description copied from interface:AsyncTaskExecutor
Submit a Runnable task for execution, receiving a Future representing that task. The Future will return anull
result upon completion.As of 6.1, this method comes with a default implementation that delegates to
TaskExecutor.execute(Runnable)
.- Specified by:
submit
in interfaceAsyncTaskExecutor
- Parameters:
task
- theRunnable
to execute (nevernull
)- Returns:
- a Future representing pending completion of the task
-
submit
Description copied from interface:AsyncTaskExecutor
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)
.- Specified by:
submit
in interfaceAsyncTaskExecutor
- Parameters:
task
- theCallable
to execute (nevernull
)- Returns:
- a Future representing pending completion of the task
-
submitListenable
Description copied from interface:AsyncListenableTaskExecutor
Submit aRunnable
task for execution, receiving aListenableFuture
representing that task. The Future will return anull
result upon completion.- Specified by:
submitListenable
in interfaceAsyncListenableTaskExecutor
- Parameters:
task
- theRunnable
to execute (nevernull
)- Returns:
- a
ListenableFuture
representing pending completion of the task
-
submitListenable
Description copied from interface:AsyncListenableTaskExecutor
Submit aCallable
task for execution, receiving aListenableFuture
representing that task. The Future will return the Callable's result upon completion.- Specified by:
submitListenable
in interfaceAsyncListenableTaskExecutor
- Parameters:
task
- theCallable
to execute (nevernull
)- Returns:
- a
ListenableFuture
representing pending completion of the task
-
doExecute
protected void doExecute(Executor concurrentExecutor, @Nullable TaskDecorator taskDecorator, Runnable runnable) throws RejectedExecutionException Actually execute the givenRunnable
(which may be a user-supplied task or a wrapper around a user-supplied task) with the given executor.- Parameters:
concurrentExecutor
- the underlying JDK concurrent executor to delegate totaskDecorator
- the specified decorator to be applied, if anyrunnable
- the runnable to execute- Throws:
RejectedExecutionException
- if the given runnable cannot be accepted- Since:
- 4.3
-