spring-framework / org.springframework.scheduling.concurrent

Package org.springframework.scheduling.concurrent

Types

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.

DefaultManagedAwareThreadFactory

open class DefaultManagedAwareThreadFactory : CustomizableThreadFactory, InitializingBean

JNDI-based variant of CustomizableThreadFactory, performing a default lookup for JSR-236's "java:comp/DefaultManagedThreadFactory" in a Java EE 7 environment, falling back to the local CustomizableThreadFactory setup if not found.

This is a convenient way to use managed threads when running in a Java EE 7 environment, simply using regular local threads otherwise - without conditional setup (i.e. without profiles).

Note: This class is not strictly JSR-236 based; it can work with any regular java.util.concurrent.ThreadFactory that can be found in JNDI. Therefore, the default JNDI name "java:comp/DefaultManagedThreadFactory" can be customized through the "jndiName" bean property.

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.

DefaultManagedTaskScheduler

open class DefaultManagedTaskScheduler : ConcurrentTaskScheduler, InitializingBean

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

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

ForkJoinPoolFactoryBean

open class ForkJoinPoolFactoryBean : FactoryBean<ForkJoinPool>, InitializingBean, DisposableBean

A Spring FactoryBean that builds and exposes a preconfigured ForkJoinPool.

For details on the ForkJoinPool API and its use with RecursiveActions, see the JDK 7 javadoc.

jsr166.jar, containing java.util.concurrent updates for Java 6, can be obtained from the concurrency interest website.

ScheduledExecutorFactoryBean

open class ScheduledExecutorFactoryBean : ExecutorConfigurationSupport, FactoryBean<ScheduledExecutorService>

org.springframework.beans.factory.FactoryBean that sets up a java.util.concurrent.ScheduledExecutorService (by default: a java.util.concurrent.ScheduledThreadPoolExecutor) and exposes it for bean references.

Allows for registration of ScheduledExecutorTask, automatically starting the ScheduledExecutorService on initialization and cancelling it on destruction of the context. In scenarios that only require static registration of tasks at startup, there is no need to access the ScheduledExecutorService instance itself in application code at all; ScheduledExecutorFactoryBean is then just being used for lifecycle integration.

For an alternative, you may set up a ScheduledThreadPoolExecutor instance directly using constructor injection, or use a factory method definition that points to the java.util.concurrent.Executors class. This is strongly recommended in particular for common @Bean methods in configuration classes, where this FactoryBean variant would force you to return the FactoryBean type instead of ScheduledExecutorService.

Note that java.util.concurrent.ScheduledExecutorService uses a Runnable instance that is shared between repeated executions, in contrast to Quartz which instantiates a new Job for each execution.

WARNING: Runnable submitted via a native java.util.concurrent.ScheduledExecutorService are removed from the execution schedule once they throw an exception. If you would prefer to continue execution after such an exception, switch this FactoryBean's "continueScheduledExecutionAfterException" property to "true".

ScheduledExecutorTask

open class ScheduledExecutorTask

JavaBean that describes a scheduled executor task, consisting of the Runnable and a delay plus period. The period needs to be specified; there is no point in a default for it.

The java.util.concurrent.ScheduledExecutorService does not offer more sophisticated scheduling options such as cron expressions. Consider using ThreadPoolTaskScheduler for such needs.

Note that the java.util.concurrent.ScheduledExecutorService mechanism uses a Runnable instance that is shared between repeated executions, in contrast to Quartz which creates a new Job instance for each execution.

ThreadPoolExecutorFactoryBean

open class ThreadPoolExecutorFactoryBean : ExecutorConfigurationSupport, FactoryBean<ExecutorService>, InitializingBean, DisposableBean

JavaBean that allows for configuring a java.util.concurrent.ThreadPoolExecutor in bean style (through its "corePoolSize", "maxPoolSize", "keepAliveSeconds", "queueCapacity" properties) and exposing it as a bean reference of its native java.util.concurrent.ExecutorService type.

For an alternative, you may set up a ThreadPoolExecutor instance directly using constructor injection, or use a factory method definition that points to the java.util.concurrent.Executors class. This is strongly recommended in particular for common @Bean methods in configuration classes, where this FactoryBean variant would force you to return the FactoryBean type instead of the actual Executor type.

If you need a timing-based java.util.concurrent.ScheduledExecutorService instead, consider ScheduledExecutorFactoryBean.

ThreadPoolTaskScheduler

open class ThreadPoolTaskScheduler : ExecutorConfigurationSupport, AsyncListenableTaskExecutor, SchedulingTaskExecutor, TaskScheduler

Implementation of Spring's TaskScheduler interface, wrapping a native java.util.concurrent.ScheduledThreadPoolExecutor.