| java.lang.Object org.springframework.scheduling.quartz.SchedulerFactoryBean
SchedulerFactoryBean | public class SchedulerFactoryBean implements FactoryBean,ApplicationContextAware,InitializingBean,DisposableBean,Lifecycle(Code) | | FactoryBean that sets up a Quartz
org.quartz.Scheduler ,
manages its lifecycle as part of the Spring application context,
and exposes the Scheduler reference for dependency injection.
Allows registration of JobDetails, Calendars and Triggers, automatically
starting the scheduler on initialization and shutting it down on destruction.
In scenarios that just require static registration of jobs at startup, there
is no need to access the Scheduler instance itself in application code.
For dynamic registration of jobs at runtime, use a bean reference to
this SchedulerFactoryBean to get direct access to the Quartz Scheduler
(org.quartz.Scheduler ). This allows you to create new jobs
and triggers, and also to control and monitor the entire Scheduler.
Note that Quartz instantiates a new Job for each execution, in
contrast to Timer which uses a TimerTask instance that is shared
between repeated executions. Just JobDetail descriptors are shared.
When using persistent jobs, it is strongly recommended to perform all
operations on the Scheduler within Spring-managed (or plain JTA) transactions.
Else, database locking will not properly work and might even break.
(See
SchedulerFactoryBean.setDataSource setDataSource javadoc for details.)
The preferred way to achieve transactional execution is to demarcate
declarative transactions at the business facade level, which will
automatically apply to Scheduler operations performed within those scopes.
Alternatively, you may add transactional advice for the Scheduler itself.
This version of Spring's SchedulerFactoryBean requires Quartz 1.5 or higher.
author: Juergen Hoeller since: 18.02.2004 See Also: SchedulerFactoryBean.setDataSource See Also: org.quartz.Scheduler See Also: org.quartz.SchedulerFactory See Also: org.quartz.impl.StdSchedulerFactory See Also: org.springframework.transaction.interceptor.TransactionProxyFactoryBean |
Method Summary | |
public void | afterPropertiesSet() | protected Scheduler | createScheduler(SchedulerFactory schedulerFactory, String schedulerName) Create the Scheduler instance for the given factory and scheduler name.
Called by afterPropertiesSet.
Default implementation invokes SchedulerFactory's getScheduler
method. | public void | destroy() Shut down the Quartz scheduler on bean factory shutdown,
stopping all scheduled jobs. | public static DataSource | getConfigTimeDataSource() Return the DataSource for the currently configured Quartz Scheduler,
to be used by LocalDataSourceJobStore.
This instance will be set before initialization of the corresponding
Scheduler, and reset immediately afterwards. | public static DataSource | getConfigTimeNonTransactionalDataSource() Return the non-transactional DataSource for the currently configured
Quartz Scheduler, to be used by LocalDataSourceJobStore.
This instance will be set before initialization of the corresponding
Scheduler, and reset immediately afterwards. | public static TaskExecutor | getConfigTimeTaskExecutor() Return the TaskExecutor for the currently configured Quartz Scheduler,
to be used by LocalTaskExecutorThreadPool.
This instance will be set before initialization of the corresponding
Scheduler, and reset immediately afterwards. | public Object | getObject() | public Class | getObjectType() | public boolean | isRunning() | public boolean | isSingleton() | public void | setApplicationContext(ApplicationContext applicationContext) | public void | setApplicationContextSchedulerContextKey(String applicationContextSchedulerContextKey) Set the key of an ApplicationContext reference to expose in the
SchedulerContext, for example "applicationContext". | public void | setAutoStartup(boolean autoStartup) Set whether to automatically start the scheduler after initialization. | public void | setCalendars(Map calendars) Register a list of Quartz Calendar objects with the Scheduler
that this FactoryBean creates, to be referenced by Triggers. | public void | setConfigLocation(Resource configLocation) Set the location of the Quartz properties config file, for example
as classpath resource "classpath:quartz.properties". | public void | setDataSource(DataSource dataSource) Set the default DataSource to be used by the Scheduler. | public void | setGlobalJobListeners(JobListener[] globalJobListeners) Specify global Quartz JobListeners to be registered with the Scheduler. | public void | setGlobalTriggerListeners(TriggerListener[] globalTriggerListeners) Specify global Quartz TriggerListeners to be registered with the Scheduler. | public void | setJobDetails(JobDetail[] jobDetails) Register a list of JobDetail objects with the Scheduler that
this FactoryBean creates, to be referenced by Triggers. | public void | setJobFactory(JobFactory jobFactory) Set the Quartz JobFactory to use for this Scheduler.
Default is Spring's
AdaptableJobFactory , which supports
java.lang.Runnable objects as well as standard Quartz
org.quartz.Job instances. | public void | setJobListeners(JobListener[] jobListeners) Specify named Quartz JobListeners to be registered with the Scheduler. | public void | setJobSchedulingDataLocation(String jobSchedulingDataLocation) Set the location of a Quartz job definition XML file that follows the
"job_scheduling_data_1_0" DTD. | public void | setJobSchedulingDataLocations(String[] jobSchedulingDataLocations) Set the locations of Quartz job definition XML files that follow the
"job_scheduling_data_1_0" DTD. | public void | setNonTransactionalDataSource(DataSource nonTransactionalDataSource) Set the DataSource to be used by the Scheduler for non-transactional access. | public void | setOverwriteExistingJobs(boolean overwriteExistingJobs) Set whether any jobs defined on this SchedulerFactoryBean should overwrite
existing job definitions. | public void | setQuartzProperties(Properties quartzProperties) Set Quartz properties, like "org.quartz.threadPool.class". | public void | setSchedulerContextAsMap(Map schedulerContextAsMap) Register objects in the Scheduler context via a given Map. | public void | setSchedulerFactoryClass(Class schedulerFactoryClass) Set the Quartz SchedulerFactory implementation to use.
Default is StdSchedulerFactory, reading in the standard
quartz.properties from quartz.jar. | public void | setSchedulerListeners(SchedulerListener[] schedulerListeners) Specify Quartz SchedulerListeners to be registered with the Scheduler. | public void | setSchedulerName(String schedulerName) Set the name of the Scheduler to fetch from the SchedulerFactory. | public void | setStartupDelay(int startupDelay) Set the number of seconds to wait after initialization before
starting the scheduler asynchronously. | public void | setTaskExecutor(TaskExecutor taskExecutor) Set the Spring TaskExecutor to use as Quartz backend. | public void | setTransactionManager(PlatformTransactionManager transactionManager) Set the transaction manager to be used for registering jobs and triggers
that are defined by this SchedulerFactoryBean. | public void | setTriggerListeners(TriggerListener[] triggerListeners) Specify named Quartz TriggerListeners to be registered with the Scheduler. | public void | setTriggers(Trigger[] triggers) Register a list of Trigger objects with the Scheduler that
this FactoryBean creates. | public void | setWaitForJobsToCompleteOnShutdown(boolean waitForJobsToCompleteOnShutdown) Set whether to wait for running jobs to complete on shutdown.
Default is "false". | public void | start() | protected void | startScheduler(Scheduler scheduler, int startupDelay) Start the Quartz Scheduler, respecting the "startupDelay" setting. | public void | stop() |
DEFAULT_THREAD_COUNT | final public static int DEFAULT_THREAD_COUNT(Code) | | |
PROP_THREAD_COUNT | final public static String PROP_THREAD_COUNT(Code) | | |
logger | final protected Log logger(Code) | | |
createScheduler | protected Scheduler createScheduler(SchedulerFactory schedulerFactory, String schedulerName) throws SchedulerException(Code) | | Create the Scheduler instance for the given factory and scheduler name.
Called by afterPropertiesSet.
Default implementation invokes SchedulerFactory's getScheduler
method. Can be overridden for custom Scheduler creation.
Parameters: schedulerFactory - the factory to create the Scheduler with Parameters: schedulerName - the name of the scheduler to create the Scheduler instance throws: SchedulerException - if thrown by Quartz methods See Also: SchedulerFactoryBean.afterPropertiesSet See Also: org.quartz.SchedulerFactory.getScheduler |
destroy | public void destroy() throws SchedulerException(Code) | | Shut down the Quartz scheduler on bean factory shutdown,
stopping all scheduled jobs.
|
getConfigTimeDataSource | public static DataSource getConfigTimeDataSource()(Code) | | Return the DataSource for the currently configured Quartz Scheduler,
to be used by LocalDataSourceJobStore.
This instance will be set before initialization of the corresponding
Scheduler, and reset immediately afterwards. It is thus only available
during configuration.
See Also: SchedulerFactoryBean.setDataSource See Also: LocalDataSourceJobStore |
getConfigTimeNonTransactionalDataSource | public static DataSource getConfigTimeNonTransactionalDataSource()(Code) | | Return the non-transactional DataSource for the currently configured
Quartz Scheduler, to be used by LocalDataSourceJobStore.
This instance will be set before initialization of the corresponding
Scheduler, and reset immediately afterwards. It is thus only available
during configuration.
See Also: SchedulerFactoryBean.setNonTransactionalDataSource See Also: LocalDataSourceJobStore |
getConfigTimeTaskExecutor | public static TaskExecutor getConfigTimeTaskExecutor()(Code) | | Return the TaskExecutor for the currently configured Quartz Scheduler,
to be used by LocalTaskExecutorThreadPool.
This instance will be set before initialization of the corresponding
Scheduler, and reset immediately afterwards. It is thus only available
during configuration.
See Also: SchedulerFactoryBean.setDataSource See Also: LocalDataSourceJobStore |
isSingleton | public boolean isSingleton()(Code) | | |
setApplicationContextSchedulerContextKey | public void setApplicationContextSchedulerContextKey(String applicationContextSchedulerContextKey)(Code) | | Set the key of an ApplicationContext reference to expose in the
SchedulerContext, for example "applicationContext". Default is none.
Only applicable when running in a Spring ApplicationContext.
Note: When using persistent Jobs whose JobDetail will be kept in the
database, do not put an ApplicationContext reference into the JobDataMap
but rather into the SchedulerContext.
In case of a QuartzJobBean, the reference will be applied to the Job
instance as bean property. An "applicationContext" attribute will
correspond to a "setApplicationContext" method in that scenario.
Note that BeanFactory callback interfaces like ApplicationContextAware
are not automatically applied to Quartz Job instances, because Quartz
itself is reponsible for the lifecycle of its Jobs.
See Also: JobDetailBean.setApplicationContextJobDataKey See Also: org.springframework.context.ApplicationContext |
setAutoStartup | public void setAutoStartup(boolean autoStartup)(Code) | | Set whether to automatically start the scheduler after initialization.
Default is "true"; set this to "false" to allow for manual startup.
|
setCalendars | public void setCalendars(Map calendars)(Code) | | Register a list of Quartz Calendar objects with the Scheduler
that this FactoryBean creates, to be referenced by Triggers.
Parameters: calendars - Map with calendar names as keys as Calendarobjects as values See Also: org.quartz.Calendar See Also: org.quartz.Trigger.setCalendarName |
setConfigLocation | public void setConfigLocation(Resource configLocation)(Code) | | Set the location of the Quartz properties config file, for example
as classpath resource "classpath:quartz.properties".
Note: Can be omitted when all necessary properties are specified
locally via this bean, or when relying on Quartz' default configuration.
See Also: SchedulerFactoryBean.setQuartzProperties |
setDataSource | public void setDataSource(DataSource dataSource)(Code) | | Set the default DataSource to be used by the Scheduler. If set,
this will override corresponding settings in Quartz properties.
Note: If this is set, the Quartz settings should not define
a job store "dataSource" to avoid meaningless double configuration.
A Spring-specific subclass of Quartz' JobStoreCMT will be used.
It is therefore strongly recommended to perform all operations on
the Scheduler within Spring-managed (or plain JTA) transactions.
Else, database locking will not properly work and might even break
(e.g. if trying to obtain a lock on Oracle without a transaction).
Supports both transactional and non-transactional DataSource access.
With a non-XA DataSource and local Spring transactions, a single DataSource
argument is sufficient. In case of an XA DataSource and global JTA transactions,
SchedulerFactoryBean's "nonTransactionalDataSource" property should be set,
passing in a non-XA DataSource that will not participate in global transactions.
See Also: SchedulerFactoryBean.setNonTransactionalDataSource See Also: SchedulerFactoryBean.setQuartzProperties See Also: SchedulerFactoryBean.setTransactionManager See Also: LocalDataSourceJobStore |
setGlobalJobListeners | public void setGlobalJobListeners(JobListener[] globalJobListeners)(Code) | | Specify global Quartz JobListeners to be registered with the Scheduler.
Such JobListeners will apply to all Jobs in the Scheduler.
|
setGlobalTriggerListeners | public void setGlobalTriggerListeners(TriggerListener[] globalTriggerListeners)(Code) | | Specify global Quartz TriggerListeners to be registered with the Scheduler.
Such TriggerListeners will apply to all Triggers in the Scheduler.
|
setJobDetails | public void setJobDetails(JobDetail[] jobDetails)(Code) | | Register a list of JobDetail objects with the Scheduler that
this FactoryBean creates, to be referenced by Triggers.
This is not necessary when a Trigger determines the JobDetail
itself: In this case, the JobDetail will be implicitly registered
in combination with the Trigger.
See Also: SchedulerFactoryBean.setTriggers See Also: org.quartz.JobDetail See Also: JobDetailBean See Also: JobDetailAwareTrigger See Also: org.quartz.Trigger.setJobName |
setJobFactory | public void setJobFactory(JobFactory jobFactory)(Code) | | Set the Quartz JobFactory to use for this Scheduler.
Default is Spring's
AdaptableJobFactory , which supports
java.lang.Runnable objects as well as standard Quartz
org.quartz.Job instances. Note that this default only applies
to a local Scheduler, not to a RemoteScheduler (where setting
a custom JobFactory is not supported by Quartz).
Specify an instance of Spring's
SpringBeanJobFactory here
(typically as an inner bean definition) to automatically populate a job's
bean properties from the specified job data map and scheduler context.
See Also: AdaptableJobFactory See Also: SpringBeanJobFactory |
setJobListeners | public void setJobListeners(JobListener[] jobListeners)(Code) | | Specify named Quartz JobListeners to be registered with the Scheduler.
Such JobListeners will only apply to Jobs that explicitly activate
them via their name.
See Also: org.quartz.JobListener.getName See Also: org.quartz.JobDetail.addJobListener See Also: JobDetailBean.setJobListenerNames |
setJobSchedulingDataLocation | public void setJobSchedulingDataLocation(String jobSchedulingDataLocation)(Code) | | Set the location of a Quartz job definition XML file that follows the
"job_scheduling_data_1_0" DTD. Can be specified to automatically
register jobs that are defined in such a file, possibly in addition
to jobs defined directly on this SchedulerFactoryBean.
See Also: ResourceJobSchedulingDataProcessor See Also: org.quartz.xml.JobSchedulingDataProcessor |
setJobSchedulingDataLocations | public void setJobSchedulingDataLocations(String[] jobSchedulingDataLocations)(Code) | | Set the locations of Quartz job definition XML files that follow the
"job_scheduling_data_1_0" DTD. Can be specified to automatically
register jobs that are defined in such files, possibly in addition
to jobs defined directly on this SchedulerFactoryBean.
See Also: ResourceJobSchedulingDataProcessor See Also: org.quartz.xml.JobSchedulingDataProcessor |
setNonTransactionalDataSource | public void setNonTransactionalDataSource(DataSource nonTransactionalDataSource)(Code) | | Set the DataSource to be used by the Scheduler for non-transactional access.
This is only necessary if the default DataSource is an XA DataSource that will
always participate in transactions: A non-XA version of that DataSource should
be specified as "nonTransactionalDataSource" in such a scenario.
This is not relevant with a local DataSource instance and Spring transactions.
Specifying a single default DataSource as "dataSource" is sufficient there.
See Also: SchedulerFactoryBean.setDataSource See Also: LocalDataSourceJobStore |
setOverwriteExistingJobs | public void setOverwriteExistingJobs(boolean overwriteExistingJobs)(Code) | | Set whether any jobs defined on this SchedulerFactoryBean should overwrite
existing job definitions. Default is "false", to not overwrite already
registered jobs that have been read in from a persistent job store.
|
setQuartzProperties | public void setQuartzProperties(Properties quartzProperties)(Code) | | Set Quartz properties, like "org.quartz.threadPool.class".
Can be used to override values in a Quartz properties config file,
or to specify all necessary properties locally.
See Also: SchedulerFactoryBean.setConfigLocation |
setSchedulerContextAsMap | public void setSchedulerContextAsMap(Map schedulerContextAsMap)(Code) | | Register objects in the Scheduler context via a given Map.
These objects will be available to any Job that runs in this Scheduler.
Note: When using persistent Jobs whose JobDetail will be kept in the
database, do not put Spring-managed beans or an ApplicationContext
reference into the JobDataMap but rather into the SchedulerContext.
Parameters: schedulerContextAsMap - Map with String keys and any objects asvalues (for example Spring-managed beans) See Also: JobDetailBean.setJobDataAsMap |
setSchedulerFactoryClass | public void setSchedulerFactoryClass(Class schedulerFactoryClass)(Code) | | Set the Quartz SchedulerFactory implementation to use.
Default is StdSchedulerFactory, reading in the standard
quartz.properties from quartz.jar. To use custom Quartz
properties, specify "configLocation" or "quartzProperties".
See Also: org.quartz.impl.StdSchedulerFactory See Also: SchedulerFactoryBean.setConfigLocation See Also: SchedulerFactoryBean.setQuartzProperties |
setSchedulerListeners | public void setSchedulerListeners(SchedulerListener[] schedulerListeners)(Code) | | Specify Quartz SchedulerListeners to be registered with the Scheduler.
|
setSchedulerName | public void setSchedulerName(String schedulerName)(Code) | | Set the name of the Scheduler to fetch from the SchedulerFactory.
If not specified, the default Scheduler will be used.
See Also: org.quartz.SchedulerFactory.getScheduler(String) See Also: org.quartz.SchedulerFactory.getScheduler |
setStartupDelay | public void setStartupDelay(int startupDelay)(Code) | | Set the number of seconds to wait after initialization before
starting the scheduler asynchronously. Default is 0, meaning
immediate synchronous startup on initialization of this bean.
Setting this to 10 or 20 seconds makes sense if no jobs
should be run before the entire application has started up.
|
setTransactionManager | public void setTransactionManager(PlatformTransactionManager transactionManager)(Code) | | Set the transaction manager to be used for registering jobs and triggers
that are defined by this SchedulerFactoryBean. Default is none; setting
this only makes sense when specifying a DataSource for the Scheduler.
See Also: SchedulerFactoryBean.setDataSource |
setTriggerListeners | public void setTriggerListeners(TriggerListener[] triggerListeners)(Code) | | Specify named Quartz TriggerListeners to be registered with the Scheduler.
Such TriggerListeners will only apply to Triggers that explicitly activate
them via their name.
See Also: org.quartz.TriggerListener.getName See Also: org.quartz.Trigger.addTriggerListener See Also: CronTriggerBean.setTriggerListenerNames See Also: SimpleTriggerBean.setTriggerListenerNames |
setTriggers | public void setTriggers(Trigger[] triggers)(Code) | | Register a list of Trigger objects with the Scheduler that
this FactoryBean creates.
If the Trigger determines the corresponding JobDetail itself,
the job will be automatically registered with the Scheduler.
Else, the respective JobDetail needs to be registered via the
"jobDetails" property of this FactoryBean.
See Also: SchedulerFactoryBean.setJobDetails See Also: org.quartz.JobDetail See Also: JobDetailAwareTrigger See Also: CronTriggerBean See Also: SimpleTriggerBean |
setWaitForJobsToCompleteOnShutdown | public void setWaitForJobsToCompleteOnShutdown(boolean waitForJobsToCompleteOnShutdown)(Code) | | Set whether to wait for running jobs to complete on shutdown.
Default is "false". Switch this to "true" if you prefer
fully completed jobs at the expense of a longer shutdown phase.
See Also: org.quartz.Scheduler.shutdown(boolean) |
startScheduler | protected void startScheduler(Scheduler scheduler, int startupDelay) throws SchedulerException(Code) | | Start the Quartz Scheduler, respecting the "startupDelay" setting.
Parameters: scheduler - the Scheduler to start Parameters: startupDelay - the number of seconds to wait before startingthe Scheduler asynchronously |
|
|