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 ScheduledExecutorTasks,
automatically starting the ScheduledExecutorService on initialization and
canceling 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. 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.
uses a Runnable instance that is shared between repeated executions,
in contrast to Quartz which instantiates a new Job for each execution.
Warning
Runnables submitted via a native
java. 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".
setPoolSize, setRemoveOnCancelPolicy, setThreadFactory, ScheduledExecutorTask, java.util.concurrent.ScheduledExecutorService , java.util.concurrent.ScheduledThreadPoolExecutor
| Modifier and Type | Field and Description |
|---|---|
| private boolean | |
| private ScheduledExecutorService | |
| private boolean | |
| private int | |
| private boolean | |
| private ScheduledExecutorTask[] |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected ScheduledExecutorService | Returns: a new ScheduledExecutorService instancethe specified pool size poolSize, ThreadFactory the ThreadFactory to use threadFactory, RejectedExecutionHandler the RejectedExecutionHandler to use rejectedExecutionHandler)Create a new |
| public ScheduledExecutorService | getObject()
Implements org. Return an instance (possibly shared or independent) of the object managed by this factory. |
| public Class | getObjectType()
Implements org. Return the type of object that this FactoryBean creates,
or |
| protected Runnable | Returns: the actual Runnable to schedule (may be a decorator)the ScheduledExecutorTask to schedule task)Determine the actual Runnable to schedule for the given task. |
| protected ExecutorService | initializeExecutor(ThreadFactory
the ThreadFactory to use threadFactory, RejectedExecutionHandler the RejectedExecutionHandler to use rejectedExecutionHandler)Implements abstract org. Create the target |
| public boolean | isSingleton()
Overrides default org. Is the object managed by this factory a singleton? |
| protected void | registerTasks(ScheduledExecutorTask[]
the specified ScheduledExecutorTasks (never empty) tasks, ScheduledExecutorService the ScheduledExecutorService to register the tasks on. executor)Register the specified |
| public void | setContinueScheduledExecutionAfterException(boolean continueScheduledExecutionAfterException)
Specify whether to continue the execution of a scheduled task after it threw an exception. |
| public void | setExposeUnconfigurableExecutor(boolean exposeUnconfigurableExecutor)
Specify whether this FactoryBean should expose an unconfigurable decorator for the created executor. |
| public void | |
| public void | setRemoveOnCancelPolicy(boolean removeOnCancelPolicy)
Set the remove-on-cancel mode on |
| public void | setScheduledExecutorTasks(ScheduledExecutorTask... scheduledExecutorTasks)
Register a list of ScheduledExecutorTask objects with the ScheduledExecutorService that this FactoryBean creates. |
| continueScheduledExecutionAfterException | back to summary |
|---|---|
| private boolean continueScheduledExecutionAfterException | |
| exposedExecutor | back to summary |
|---|---|
| private ScheduledExecutorService exposedExecutor
| |
| exposeUnconfigurableExecutor | back to summary |
|---|---|
| private boolean exposeUnconfigurableExecutor | |
| poolSize | back to summary |
|---|---|
| private int poolSize | |
| removeOnCancelPolicy | back to summary |
|---|---|
| private boolean removeOnCancelPolicy | |
| scheduledExecutorTasks | back to summary |
|---|---|
| private ScheduledExecutorTask[] scheduledExecutorTasks
| |
| ScheduledExecutorFactoryBean | back to summary |
|---|---|
| public ScheduledExecutorFactoryBean() | |
| createExecutor | back to summary |
|---|---|
| protected ScheduledExecutorService createExecutor(int poolSize, ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) Create a new The default implementation creates a
| |
| getObject | back to summary |
|---|---|
| public ScheduledExecutorService getObject() Implements org. Doc from org. Return an instance (possibly shared or independent) of the object managed by this factory. As with a If this FactoryBean is not fully initialized yet at the time of
the call (for example because it is involved in a circular reference),
throw a corresponding As of Spring 2.0, FactoryBeans are allowed to return
| |
| getObjectType | back to summary |
|---|---|
| public Class Implements org. Doc from org. Return the type of object that this FactoryBean creates,
or This allows one to check for specific types of beans without instantiating objects, for example on autowiring. In the case of implementations that are creating a singleton object, this method should try to avoid singleton creation as far as possible; it should rather estimate the type in advance. For prototypes, returning a meaningful type here is advisable too. This method can be called before this FactoryBean has been fully initialized. It must not rely on state created during initialization; of course, it can still use such state if available. Note Autowiring will simply ignore FactoryBeans that return
| |
| getRunnableToSchedule | back to summary |
|---|---|
| protected Runnable getRunnableToSchedule(ScheduledExecutorTask task) Determine the actual Runnable to schedule for the given task. Wraps the task's Runnable in a
| |
| initializeExecutor | back to summary |
|---|---|
| protected ExecutorService initializeExecutor(ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) Implements abstract org. Doc from org. Create the target
| |
| isSingleton | back to summary |
|---|---|
| public boolean isSingleton() Overrides default org. Doc from org. Is the object managed by this factory a singleton? That is,
will Note If a FactoryBean indicates to hold a singleton object,
the object returned from The singleton status of the FactoryBean itself will generally be provided by the owning BeanFactory; usually, it has to be defined as singleton there. Note This method returning The default implementation returns
| |
| registerTasks | back to summary |
|---|---|
| protected void registerTasks(ScheduledExecutorTask[] tasks, ScheduledExecutorService executor) Register the specified
| |
| setContinueScheduledExecutionAfterException | back to summary |
|---|---|
| public void setContinueScheduledExecutionAfterException(boolean continueScheduledExecutionAfterException) Specify whether to continue the execution of a scheduled task after it threw an exception. Default is "false", matching the native behavior of a
| |
| setExposeUnconfigurableExecutor | back to summary |
|---|---|
| public void setExposeUnconfigurableExecutor(boolean exposeUnconfigurableExecutor) Specify whether this FactoryBean should expose an unconfigurable decorator for the created executor. Default is "false", exposing the raw executor as bean reference. Switch this flag to "true" to strictly prevent clients from modifying the executor's configuration. | |
| setPoolSize | back to summary |
|---|---|
| public void setPoolSize(int poolSize) Set the ScheduledExecutorService's pool size. Default is 1. | |
| setRemoveOnCancelPolicy | back to summary |
|---|---|
| public void setRemoveOnCancelPolicy(boolean removeOnCancelPolicy) Set the remove-on-cancel mode on Default is | |
| setScheduledExecutorTasks | back to summary |
|---|---|
| public void setScheduledExecutorTasks(ScheduledExecutorTask... scheduledExecutorTasks) Register a list of ScheduledExecutorTask objects with the ScheduledExecutorService that this FactoryBean creates. Depending on each ScheduledExecutorTask's settings, it will be registered via one of ScheduledExecutorService's schedule methods.
| |