Quartz Scheduler Developer Guide : Key Interfaces
Key Interfaces
The key interfaces of the Quartz API are:
*Scheduler - the main API for interacting with the Scheduler.
*Job - an interface to be implemented by components that you want the Scheduler to execute.
*JobDetail - used to define instances of Jobs.
*Trigger - a component that defines the schedule upon which a given Job will be executed.
*JobBuilder - used to define/build JobDetail instances, which define instances of Jobs.
*TriggerBuilder - used to define/build Trigger instances.
A Scheduler’s life-cycle is bounded by its creation, via a SchedulerFactory and a call to its shutdown() method.
Once created the Scheduler interface can be used add, remove, and list jobs and triggers, and perform other scheduling-related operations (such as pausing a trigger). However, the Scheduler will not actually act on any triggers (execute jobs) until it has been started with the start() method, as shown in Instantiating the Scheduler.
Quartz provides "builder" classes that define a Domain Specific Language (or DSL, also sometimes referred to as a "fluent interface"). Here is an example:
// define the job and tie it to our HelloJob class
JobDetail job = newJob(HelloJob.class)
.withIdentity("myJob", "group1") // name "myJob", group "group1"
.build();

// Trigger the job to run now, and then every 40 seconds
Trigger trigger = newTrigger()
.withIdentity("myTrigger", "group1")
.startNow()
.withSchedule(simpleSchedule()
.withIntervalInSeconds(40)
.repeatForever())
.build();

// Tell quartz to schedule the job using our trigger
sched.scheduleJob(job, trigger);
The block of code that builds the job definition is using methods that were statically imported from the JobBuilder class. Likewise, the block of code that builds the trigger is using methods imported from the TriggerBuilder class - as well as from the SimpleScheduleBulder class.
The static imports of the DSL can be achieved through import statements such as these:
import static org.quartz.JobBuilder.*;
import static org.quartz.SimpleScheduleBuilder.*;
import static org.quartz.CronScheduleBuilder.*;
import static org.quartz.CalendarIntervalScheduleBuilder.*;
import static org.quartz.TriggerBuilder.*;
import static org.quartz.DateBuilder.*;
The various ScheduleBuilder classes have methods relating to defining different types of schedules.
The DateBuilder class contains various methods for easily constructing java.util.Date instances for particular points in time (such as a date that represents the next even hour - or in other words 10:00:00 if it is currently 9:43:27).
Copyright © 2010-2015 Software AG, Darmstadt, Germany.

Product Logo |   Feedback