spring-framework / org.springframework.scheduling.concurrent / ScheduledExecutorFactoryBean / <init>

<init>

ScheduledExecutorFactoryBean()

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".

Author
Juergen Hoeller

Since
2.0

See Also
#setPoolSize#setRemoveOnCancelPolicy#setThreadFactoryScheduledExecutorTaskjava.util.concurrent.ScheduledExecutorServicejava.util.concurrent.ScheduledThreadPoolExecutor