spring-framework / org.springframework.scheduling.concurrent / ConcurrentTaskExecutor

ConcurrentTaskExecutor

open class ConcurrentTaskExecutor : AsyncListenableTaskExecutor, SchedulingTaskExecutor

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 javax.enterprise.concurrent.ManagedExecutorService in order to expose javax.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 Java EE 7 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.Executorjava.util.concurrent.ExecutorServicejava.util.concurrent.ThreadPoolExecutorjava.util.concurrent.ExecutorsDefaultManagedTaskExecutorThreadPoolTaskExecutor

Constructors

<init>

ConcurrentTaskExecutor()

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

ConcurrentTaskExecutor(executor: Executor)

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

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

Functions

execute

open fun execute(task: Runnable): Unit
open fun execute(task: Runnable, startTimeout: Long): Unit

getConcurrentExecutor

fun getConcurrentExecutor(): Executor

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

prefersShortLivedTasks

open fun prefersShortLivedTasks(): Boolean

This task executor prefers short-lived work units.

setConcurrentExecutor

fun setConcurrentExecutor(executor: Executor): Unit

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

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

setTaskDecorator

fun setTaskDecorator(taskDecorator: TaskDecorator): Unit

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.

submit

open fun submit(task: Runnable): Future<*>
open fun <T : Any> submit(task: Callable<T>): Future<T>

submitListenable

open fun submitListenable(task: Runnable): ListenableFuture<*>
open fun <T : Any> submitListenable(task: Callable<T>): ListenableFuture<T>

Inheritors

DefaultManagedTaskExecutor

open class DefaultManagedTaskExecutor : ConcurrentTaskExecutor, InitializingBean

JNDI-based variant of ConcurrentTaskExecutor, performing a default lookup for JSR-236's "java:comp/DefaultManagedExecutorService" in a Java EE 7 environment.

Note: This class is not strictly JSR-236 based; it can work with any regular java.util.concurrent.Executor that can be found in JNDI. The actual adapting to javax.enterprise.concurrent.ManagedExecutorService happens in the base class ConcurrentTaskExecutor itself.