Interface Scheduler
- All Known Implementing Classes:
QuartzScheduler
A Scheduler maintains a registry of s and JobDetail
s. Once registered, the TriggerScheduler is
responsible for executing Job s when their associated Trigger s fire
(when their scheduled time arrives).
Scheduler instances are produced by a . A
scheduler that has already been created/initialized can be found and used through the same
factory that produced it. After a SchedulerFactoryScheduler has been created, it is in "stand-by"
mode, and must have its start() method called before it will fire any Job
s.
Job s are to be created by the 'client program', by defining a class that
implements the interface. Job
objects are then created (also by the client) to define a individual instances of the JobDetailJob
. JobDetail instances can then be registered with the Scheduler
via the scheduleJob(JobDetail, Trigger) or addJob(JobDetail, boolean)
method.
Trigger s can then be defined to fire individual Job instances based
on given schedules. SimpleTrigger s are most useful for one-time firings, or firing
at an exact moment in time, with N repeats with a given delay between them. CronTrigger
s allow scheduling based on time of day, day of week, day of month, and month of year.
Job s and Trigger s have a name and group associated with them,
which should uniquely identify them within a single . The 'group'
feature may be useful for creating logical groupings or categorizations of SchedulerJobs s
and Triggerss. If you don't have need for assigning a group to a given Jobs
of Triggers, then you can use the DEFAULT_GROUP constant
defined on this interface.
Stored Job s can also be 'manually' triggered through the use of the
triggerJob(String jobName, String jobGroup) function.
Client programs may also be interested in the 'listener' interfaces that are available from
Quartz. The interface provides notifications of JobListenerJob
executions. The interface provides notifications of TriggerListener
Trigger firings. The interface provides
notifications of SchedulerListenerScheduler events and errors. Listeners can be associated with local
schedulers through the ListenerManager interface.
The setup/configuration of a Scheduler instance is very customizable. Please
consult the documentation distributed with Quartz.
- Author:
- James House, Sharada Jambula
-
Method Summary
Modifier and TypeMethodDescriptionvoidAdd the givenJobto the Scheduler - with no associatedTrigger.voidDelete the identifiedJobfrom the Scheduler - and any associatedTriggers.Return a list ofJobExecutionContextobjects that represent all currently executing Jobs in this Scheduler instance.getJobDetail(String jobKey) Get thefor theJobDetailJobinstance with the given key.Get the keys of all thein the matching groups.JobDetailsGet a reference to the scheduler'sListenerManager, through which listeners may be registered.getTrigger(String triggerKey) Get theinstance with the given key.TriggergetTriggersOfJob(String jobKey) booleanReports whether theScheduleris in stand-by mode.booleanReports whether theSchedulerhas been shutdown.booleanWhether the scheduler has been started.rescheduleJob(String triggerName, OperableTrigger newTrigger) Remove (delete) thewith the given key, and store the new given one - which must be associated with the same job (the new trigger must have the job name specified) - however, the new trigger need not have the same name as the old trigger.OperableTriggerscheduleJob(JobDetail jobDetail, OperableTrigger trigger) Add the givento the Scheduler, and associate the givenJobDetailwith it.OperableTriggerscheduleJob(OperableTrigger trigger) voidsetJobFactory(JobFactory factory) Set theJobFactorythat will be responsible for producing instances ofJobclasses.voidshutdown()Halts theScheduler's firing of, and cleans up all resources associated with the Scheduler.Triggersvoidstandby()Temporarily halts theScheduler's firing of.Triggersvoidstart()Starts theScheduler's threads that fire.TriggersvoidstartDelayed(int seconds) Calls {#start()} after the indicated number of seconds.voidtriggerJob(String jobKey, JobDataMap data) Trigger the identified(execute it now).JobDetailvoidunscheduleJob(String triggerKey) Remove the indicatedfrom the scheduler.Trigger
-
Method Details
-
start
Starts theScheduler's threads that fire. When a scheduler is first created it is in "stand-by" mode, and will not fire triggers. The scheduler can also be put into stand-by mode by calling theTriggersstandby()method.The misfire/recovery process will be started, if it is the initial call to this method on this scheduler instance.
- Throws:
SchedulerException- ifshutdown()has been called, or there is an error within theScheduler.
-
startDelayed
Calls {#start()} after the indicated number of seconds. (This call does not block). This can be useful within applications that have initializers that create the scheduler immediately, before the resources needed by the executing jobs have been fully initialized.- Throws:
SchedulerException- ifshutdown()has been called, or there is an error within theScheduler.
-
isStarted
Whether the scheduler has been started.Note: This only reflects whether
has ever been called on this Scheduler, so it will returnstart()trueeven if theScheduleris currently in standby mode or has been since shutdown.- Throws:
SchedulerException
-
standby
Temporarily halts theScheduler's firing of.TriggersWhen
start()is called (to bring the scheduler out of stand-by mode), trigger misfire instructions will NOT be applied during the execution of thestart()method - any misfires will be detected immediately afterward (by theJobStore's normal process).The scheduler is not destroyed, and can be re-started at any time.
- Throws:
SchedulerException
-
isInStandbyMode
Reports whether theScheduleris in stand-by mode.- Throws:
SchedulerException
-
shutdown
Halts theScheduler's firing of, and cleans up all resources associated with the Scheduler.TriggersThe scheduler cannot be re-started.
- Throws:
SchedulerException
-
isShutdown
Reports whether theSchedulerhas been shutdown.- Throws:
SchedulerException
-
getCurrentlyExecutingJobs
Return a list ofJobExecutionContextobjects that represent all currently executing Jobs in this Scheduler instance.This method is not cluster aware. That is, it will only return Jobs currently executing in this Scheduler instance, not across the entire cluster.
Note that the list returned is an 'instantaneous' snap-shot, and that as soon as it's returned, the true list of executing jobs may be different. Also please read the doc associated with
JobExecutionContext- especially if you're using RMI.- Throws:
SchedulerException
-
getJobKeys
Get the keys of all thein the matching groups.JobDetails- Returns:
- Set of all keys matching
- Throws:
SchedulerException- On error
-
setJobFactory
Set theJobFactorythat will be responsible for producing instances ofJobclasses.JobFactories may be of use to those wishing to have their application produce
Jobinstances via some special mechanism, such as to give the opportunity for dependency injection.- Throws:
SchedulerException
-
getListenerManager
Get a reference to the scheduler'sListenerManager, through which listeners may be registered.- Returns:
- the scheduler's
ListenerManager - Throws:
SchedulerException- if the scheduler is not local
-
scheduleJob
Add the givento the Scheduler, and associate the givenJobDetailwith it.OperableTriggerIf the given Trigger does not reference any
Job, then it will be set to reference the Job passed with it into this method.- Throws:
SchedulerException- if the Job or Trigger cannot be added to the Scheduler, or there is an internal Scheduler error.
-
scheduleJob
- Throws:
SchedulerException- if the indicated Job does not exist, or the Trigger cannot be added to the Scheduler, or there is an internal Scheduler error.
-
rescheduleJob
Remove (delete) thewith the given key, and store the new given one - which must be associated with the same job (the new trigger must have the job name specified) - however, the new trigger need not have the same name as the old trigger.OperableTrigger- Parameters:
triggerName- identity of the trigger to replacenewTrigger- The newTriggerto be stored.- Returns:
nullif aTriggerwith the given name invalid input: '&' group was not found and removed from the store, otherwise the first fire time of the newly scheduled trigger.- Throws:
SchedulerException
-
addJob
Add the givenJobto the Scheduler - with no associatedTrigger. TheJobwill be 'dormant' until it is scheduled with aTrigger, orScheduler.triggerJob()is called for it.The
Jobmust by definition be 'durable', if it is not, SchedulerException will be thrown.- Throws:
SchedulerException- if there is an internal Scheduler error, or if the Job is not durable, or a Job with the same name already exists, andreplaceisfalse.
-
triggerJob
Trigger the identified(execute it now).JobDetail- Parameters:
data- the (possiblynull) JobDataMap to be associated with the trigger that fires the job immediately.- Throws:
SchedulerException
-
getTriggersOfJob
Get alls that are associated with the identifiedTrigger.JobDetailThe returned Trigger objects will be snap-shots of the actual stored triggers. If you wish to modify a trigger, you must re-store the trigger afterward (e.g. see
).invalid @link
#rescheduleJob(TriggerKey, Trigger)- Throws:
SchedulerException
-
getJobDetail
Get thefor theJobDetailJobinstance with the given key.The returned JobDetail object will be a snap-shot of the actual stored JobDetail. If you wish to modify the JobDetail, you must re-store the JobDetail afterward (e.g. see
).invalid @link
#addJob(JobDetail, boolean)- Throws:
SchedulerException
-
getTrigger
Get theinstance with the given key.TriggerThe returned Trigger object will be a snap-shot of the actual stored trigger. If you wish to modify the trigger, you must re-store the trigger afterward (e.g. see
).invalid @link
#rescheduleJob(TriggerKey, Trigger)- Throws:
SchedulerException
-
deleteJob
Delete the identifiedJobfrom the Scheduler - and any associatedTriggers.- Throws:
SchedulerException- if there is an internal Scheduler error.
-
unscheduleJob
Remove the indicatedfrom the scheduler.TriggerIf the related job does not have any other triggers, and the job is not durable, then the job will also be deleted.
- Throws:
SchedulerException
-
getCascadingClassLoadHelper
CascadingClassLoadHelper getCascadingClassLoadHelper()
-