Interface Scheduler
- All Known Implementing Classes:
QuartzScheduler
A Scheduler
maintains a registry of
s and JobDetail
s. Once registered, the Trigger
Scheduler
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 SchedulerFactory
Scheduler
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 JobDetail
Job
. 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 Scheduler
Jobs
s
and Triggers
s. 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 JobListener
Job
executions. The
interface provides notifications of TriggerListener
Trigger
firings. The
interface provides
notifications of SchedulerListener
Scheduler
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 TypeMethodDescriptionvoid
Add the givenJob
to the Scheduler - with no associatedTrigger
.void
Delete the identifiedJob
from the Scheduler - and any associatedTrigger
s.Return a list ofJobExecutionContext
objects that represent all currently executing Jobs in this Scheduler instance.getJobDetail
(String jobKey) Get the
for theJobDetail
Job
instance with the given key.Get the keys of all the
in the matching groups.JobDetail
sGet a reference to the scheduler'sListenerManager
, through which listeners may be registered.getTrigger
(String triggerKey) Get the
instance with the given key.Trigger
getTriggersOfJob
(String jobKey) boolean
Reports whether theScheduler
is in stand-by mode.boolean
Reports whether theScheduler
has been shutdown.boolean
Whether the scheduler has been started.rescheduleJob
(String triggerName, OperableTrigger newTrigger) Remove (delete) the
with 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
scheduleJob
(JobDetail jobDetail, OperableTrigger trigger) Add the given
to the Scheduler, and associate the givenJobDetail
with it.OperableTrigger
scheduleJob
(OperableTrigger trigger) void
setJobFactory
(JobFactory factory) Set theJobFactory
that will be responsible for producing instances ofJob
classes.void
shutdown()
Halts theScheduler
's firing of
, and cleans up all resources associated with the Scheduler.Trigger
svoid
standby()
Temporarily halts theScheduler
's firing of
.Trigger
svoid
start()
Starts theScheduler
's threads that fire
.Trigger
svoid
startDelayed
(int seconds) Calls {#start()} after the indicated number of seconds.void
triggerJob
(String jobKey, JobDataMap data) Trigger the identified
(execute it now).JobDetail
void
unscheduleJob
(String triggerKey) Remove the indicated
from 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 theTrigger
sstandby()
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()
true
even if theScheduler
is currently in standby mode or has been since shutdown.- Throws:
SchedulerException
-
standby
Temporarily halts theScheduler
's firing of
.Trigger
sWhen
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 theScheduler
is in stand-by mode.- Throws:
SchedulerException
-
shutdown
Halts theScheduler
's firing of
, and cleans up all resources associated with the Scheduler.Trigger
sThe scheduler cannot be re-started.
- Throws:
SchedulerException
-
isShutdown
Reports whether theScheduler
has been shutdown.- Throws:
SchedulerException
-
getCurrentlyExecutingJobs
Return a list ofJobExecutionContext
objects 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 the
in the matching groups.JobDetail
s- Returns:
- Set of all keys matching
- Throws:
SchedulerException
- On error
-
setJobFactory
Set theJobFactory
that will be responsible for producing instances ofJob
classes.JobFactories may be of use to those wishing to have their application produce
Job
instances 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 given
to the Scheduler, and associate the givenJobDetail
with it.OperableTrigger
If 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) the
with 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 newTrigger
to be stored.- Returns:
null
if aTrigger
with 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 givenJob
to the Scheduler - with no associatedTrigger
. TheJob
will be 'dormant' until it is scheduled with aTrigger
, orScheduler.triggerJob()
is called for it.The
Job
must 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, andreplace
isfalse
.
-
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 all
s that are associated with the identifiedTrigger
JobDetail
The 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 the
for theJobDetail
Job
instance 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 the
instance with the given key.Trigger
The 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 identifiedJob
from the Scheduler - and any associatedTrigger
s.- Throws:
SchedulerException
- if there is an internal Scheduler error.
-
unscheduleJob
Remove the indicated
from the scheduler.Trigger
If 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()
-