2. About
⢠Quartz is a richly featured, open source job scheduling library that
can be integrated within virtually any Java applicationÂť
⢠First Release 10/Apr/09 --
https://jira.terracotta.org/jira/browse/QTZ?selectedTab=com.atlassia
n.jira.jira-projects-plugin:changelog-panel&allVersions=true
⢠https://github.com/quartz-scheduler/quartz
⢠http://www.quartz-scheduler.org/
4. Runtime Environments
⢠Quartz, can run embeded within another Standalone Application
⢠Can be instantiated within an application server(or servlet
container), and participate XA transactions.
⢠Can run as a stand-alone program, to be used via RMI
⢠Can be instantiated as a cluster
5. Job Scheduling
⢠at a certain time of day (to the millisecond)
⢠on certain days of the week
⢠on certain days of the month
⢠on certain days of the year
⢠not on certain days listed within a registered Calendar (such as
business holidays)
⢠repeated a specific number of times
⢠repeated until a specific time/date
⢠repeated indefinitely
⢠repeated with a delay interval
6. Job Execution
⢠Jobs can be any Java class that implements Job interface
⢠Job and TriggerListener can be notified
⢠Actions can be instructed according to returncode such as immediate
re-execution of the Job
7. Job Persistance
⢠Storage of jobs and triggers
⢠RAMJobStore
⢠JDBCJobStore(Container Managed Transactions, Unmanaged)
⢠Terracota Job Store(without need for a backing DB)
8. Transactions
⢠Can participate in JTA transactions
⢠Can manage Transactions(works for all jobs or per job with
@ExecuteInJTATransaction Annotation)
9. Clustering
⢠Fail-over
⢠Load Balancing
⢠Quartzâs built-in clustering features rely upon database persistence
via JDBCJobStore.
⢠Terracotta extensions to Quartz provide clustering capabilities
without the need for a backing database.
10. Listeners & Plug-Ins
⢠Applications can catch scheduling events to monitor or control
job/trigger behavior by implementing one or more listener interfaces.
⢠The Plug-In mechanism can be used add functionality to Quartz, such
keeping a history of job executions, or loading job and trigger
definitions from a file.
⢠Quartz ships with a number of âfactory builtâ plug-ins and listeners.
11. The Quartz API
⢠Scheduler - the main API for interacting with the scheduler.
⢠Job - an interface to be implemented by components that you wish to
have executed by the scheduler.
⢠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.
14. Jobs And Job Details
⢠Job.execute(JobExecutionContext context)
⢠JobDetail
⢠jobClass
⢠durability
⢠requestsRecovery
⢠description
⢠key
⢠jobDataMap
⢠JobDataMap->Map<String,? Extends Serializable>
⢠Only usage of primitiveTypes and String is encourged.(Class-versioning problems
can occur with serialized Objects)
15. Job â Instances,State and Concurrency
⢠JobDetail -> job or job definition
⢠Each Execution of a Job Detail -> Job Instance
⢠A Class implements org.quartz.Job -> job class
⢠A new instance of the job class is created for each execution
⢠@DisallowConcurrentExecution -> an annotation on a Job Class. Tell
Quartz not to execute multiple instances of a given job definition
concurrently.
⢠@PersistJobDataAfterExecution -> update the stored copy of
JobDetailâs JobDataMap.
16. Job â Durability,RequestRecovery
⢠Durability -> if a job is non-durable, it is automatically deleted from
the scheduler once there are no longer active triggers associated with
it.
⢠RequestRecovery -> if a job ârequests recoveryâ, and it is executing
during the time of a âhard shutdownâ of the scheduler (i.e. the
process it is running within crashes, or the machine is shut off), then
it is re-executed when the scheduler is started again. In this case, the
JobExecutionContext.isRecovering() method will return true.
17. Job â JobExecutionException
⢠Only type of exception can be thrown from Job.execute method.
⢠Can be interpreted as directives to Scheduler.
⢠RE_EXECUTE_JOB
⢠SET_TRIGGER_COMPLETE
⢠SET_ALL_JOB_TRIGGERS_COMPLETE
23. Listeners â Job, Trigger Listener
⢠Registered with the Scheduler.ListenerManager
⢠Not Stored in the Job Store. Need to be re-registered in each run
26. JobStores - RAMJobStore
⢠The simplest JobStore to use
⢠The most performant(in terms of CPU time)
⢠Keeps all of its data in RAM
⢠When the application ends (or crashes) all of the scheduling
information is lost
⢠Config -> org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
27. JobStores â JDBCJobStore
⢠Keeps all of its data in a database via JDBC
⢠Works with nearly any database
⢠Table-creation SQL scripts are shipped with the
distribution.(docs/dbTables)
⢠All the tables start with the prefix(default QRTZ) which can be changed
(org.quartz.jobStore.tablePrefix = SMG_)
⢠JobStoreTX -> Quartz Managed Transactions
⢠JobStoreCMT -> Container Managed Transactions
⢠org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
⢠org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreCMT
31. Logging
⢠Uses the SLF4J Framework
⢠Plugins can be enabled for capturing extra information about trigger
firings and job executions.
⢠org.quartz.plugins.history.LoggingJobHistoryPlugin
⢠org.quartz.plugins.history.LoggingTriggerHistoryPlugin
32. Clustering
⢠Works with the JDBC-Jobstore and TerracottaJobStore
⢠Clustering on seperate machines needs clock synchronization.
⢠Each instance in the cluster should use the same copy of the
quartz.properties
⢠Exceptions:
⢠Different Thread Pool Size
⢠InstanceId
⢠Only one node will fire the job for each firing.
36. FAQ
⢠How do I chain Job execution? How do I create a workflow?
⢠There currently is no "direct" or "free" way to chain triggers with Quartz
⢠What are the available alternatives to Quartz?
⢠There are no known competing open source projects
⢠Commercially, you will want to look at the well-regarded Flux scheduler.