public class QuartzSchedulerFactory extends SchedulerAccessor
Scheduler.
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.
Scheduler,
SchedulerFactory,
StdSchedulerFactory| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_THREAD_COUNT
The DEFAULT_THREAD_COUNT constant.
|
static String |
PROP_THREAD_COUNT
The PROP_THREAD_COUNT constant.
|
JOB_DETAIL_KEY, logger| Constructor and Description |
|---|
QuartzSchedulerFactory() |
| Modifier and Type | Method and Description |
|---|---|
void |
addJob(org.quartz.JobDetail jobDetail)
Add a job.
|
void |
addTrigger(org.quartz.Trigger trigger)
Add trigger and the trigger's job detail.
|
void |
addTrigger(org.quartz.Trigger trigger,
org.quartz.JobDetail jobDetail)
Add a trigger with the specified job detail.
|
protected org.quartz.Scheduler |
createScheduler(org.quartz.SchedulerFactory schedulerFactory,
String schedulerName)
Create the Scheduler instance for the given factory and scheduler name.
|
void |
destroy()
Shut down the Quartz scheduler on factory shutdown,
stopping all scheduled jobs.
|
org.quartz.Scheduler |
getScheduler()
Method that determines the Scheduler to operate on.
|
void |
initialize()
This method allows the instance to perform initialization only
possible when all bean properties have been set and to throw an
exception in the event of misconfiguration.
|
boolean |
isRunning()
Reports whether the
Scheduler is in stand-by mode. |
void |
setConfigLocation(ResourceBundle configLocation)
Set the location of the Quartz properties config file, for example
as classpath resource "classpath:quartz.properties".
|
void |
setExposeSchedulerInRepository(boolean exposeSchedulerInRepository)
Set whether to expose the
Scheduler instance in the
Quartz SchedulerRepository. |
void |
setJobFactory(org.quartz.spi.JobFactory jobFactory)
Set the Quartz JobFactory to use for this Scheduler.
|
void |
setQuartzProperties(Properties quartzProperties)
Set Quartz properties, like "org.quartz.threadPool.class".
|
void |
setSchedulerFactoryClass(Class<? extends org.quartz.SchedulerFactory> schedulerFactoryClass)
Set the Quartz SchedulerFactory implementation to use.
|
void |
setSchedulerName(String schedulerName)
Set the name of the Scheduler to create via the SchedulerFactory.
|
void |
setWaitForJobsToCompleteOnShutdown(boolean waitForJobsToCompleteOnShutdown)
Set whether to wait for running jobs to complete on shutdown.
|
void |
start()
Start the scheduler immediately.
|
void |
start(int startupDelay)
Start the scheduler, respecting the "startupDelay" setting.
|
protected void |
startScheduler(org.quartz.Scheduler scheduler,
int startupDelay)
Start the Quartz Scheduler, respecting the "startupDelay" setting.
|
void |
stop()
Temporarily halts the
Scheduler's firing of . |
void |
stop(Runnable callback)
Call
callback.run() after stop(). |
void |
triggerJob(org.quartz.JobKey jobKey)
Trigger the identified
JobDetail (execute it now). |
addJobToScheduler, addTriggerToScheduler, registerJobsAndTriggers, registerListeners, setCalendars, setGlobalJobListeners, setGlobalTriggerListeners, setJobDetails, setJobSchedulingDataLocation, setJobSchedulingDataLocations, setOverwriteExistingJobs, setSchedulerListeners, setTriggerspublic static final String PROP_THREAD_COUNT
public static final int DEFAULT_THREAD_COUNT
public void setSchedulerFactoryClass(Class<? extends org.quartz.SchedulerFactory> schedulerFactoryClass)
Default is StdSchedulerFactory, reading in the standard
quartz.properties from quartz.jar.
To use custom Quartz properties, specify the "configLocation"
or "quartzProperties" bean property on this FactoryBean.
StdSchedulerFactory,
setConfigLocation(java.util.ResourceBundle),
setQuartzProperties(java.util.Properties)public void setSchedulerName(String schedulerName)
If not specified, the bean name will be used as default scheduler name.
SchedulerFactory.getScheduler(),
SchedulerFactory.getScheduler(String)public void setConfigLocation(ResourceBundle configLocation)
Note: Can be omitted when all necessary properties are specified locally via this bean, or when relying on Quartz' default configuration.
public void setQuartzProperties(Properties quartzProperties)
Can be used to override values in a Quartz properties config file, or to specify all necessary properties locally.
public void setJobFactory(org.quartz.spi.JobFactory jobFactory)
Default is QuartzJobFactory, which supports
IScheduledJob objects as well as standard 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).
QuartzJobFactorypublic void setExposeSchedulerInRepository(boolean exposeSchedulerInRepository)
Scheduler instance in the
Quartz SchedulerRepository. Default is "false", since the
Scheduler is usually exclusively intended for access within the context.
Switch this flag to "true" in order to expose the Scheduler globally. This is not recommended unless you have an existing application that relies on this behavior.
public void setWaitForJobsToCompleteOnShutdown(boolean waitForJobsToCompleteOnShutdown)
Default is "false". Switch this to "true" if you prefer fully completed jobs at the expense of a longer shutdown phase.
Scheduler.shutdown(boolean)public void initialize()
throws Exception
Exception - in the event of misconfiguration (such
as failure to set an essential property) or if initialization fails.protected org.quartz.Scheduler createScheduler(org.quartz.SchedulerFactory schedulerFactory,
String schedulerName)
throws org.quartz.SchedulerException
initialize().
The default implementation invokes SchedulerFactory's getScheduler
method. Can be overridden for custom Scheduler creation.
schedulerFactory - the factory to create the Scheduler withschedulerName - the name of the scheduler to createorg.quartz.SchedulerException - if thrown by Quartz methodsinitialize(),
SchedulerFactory.getScheduler()protected void startScheduler(org.quartz.Scheduler scheduler,
int startupDelay)
throws org.quartz.SchedulerException
scheduler - the Scheduler to startstartupDelay - the number of seconds to wait before starting
the Scheduler asynchronouslyorg.quartz.SchedulerException - if could not start Quartz Scheduler.public org.quartz.Scheduler getScheduler()
getScheduler in class SchedulerAccessorpublic void start()
throws org.quartz.SchedulerException
org.quartz.SchedulerException - if could not start Quartz Scheduler.public void start(int startupDelay)
throws org.quartz.SchedulerException
startupDelay - the number of seconds to wait before startingorg.quartz.SchedulerException - if could not start Quartz Scheduler.public void stop()
throws org.quartz.SchedulerException
Scheduler's firing of Triggers.
When start() is called (to bring the scheduler out of
stand-by mode), trigger misfire instructions will NOT be applied
during the execution of the start() method - any misfires
will be detected immediately afterward (by the JobStore's
normal process).
The scheduler is not destroyed, and can be re-started at any time.
org.quartz.SchedulerExceptionstart()public void stop(Runnable callback) throws org.quartz.SchedulerException
callback.run() after stop().callback - the callback.org.quartz.SchedulerException - if could not start Quartz Scheduler.public boolean isRunning()
Scheduler is in stand-by mode.public void destroy()
throws org.quartz.SchedulerException
org.quartz.SchedulerExceptionpublic void addJob(org.quartz.JobDetail jobDetail)
throws org.quartz.SchedulerException
jobDetail - the job detail.org.quartz.SchedulerException - if could not start Quartz Scheduler.public void addTrigger(org.quartz.Trigger trigger,
org.quartz.JobDetail jobDetail)
throws org.quartz.SchedulerException
trigger - the trigger.jobDetail - the job detail.org.quartz.SchedulerException - if could not start Quartz Scheduler.public void addTrigger(org.quartz.Trigger trigger)
throws org.quartz.SchedulerException
trigger - the trigger.org.quartz.SchedulerException - if could not start Quartz Scheduler.public void triggerJob(org.quartz.JobKey jobKey)
throws org.quartz.SchedulerException
JobDetail (execute it now).jobKey - org.quartz.SchedulerExceptionCopyright © 2017. All rights reserved.