Quartz concepts

Basic concepts

  • Job: What to do
  • Trigger: When to do it
  • Scheduler: The director to associate triggers to jobs and to invoke the trigger

A job can be associated with several triggers, but a trigger should not be used to trigger more than one job

Go into details for some depth

  • JobKey = Job Name + Job Group, TriggerKey = Trigger Name + Trigger Group: The `name` and `namespace` of these things, i.e. the ID
  • Jod Data Map: The context for jobs or triggers

Somethings that may be confusing

  • Job detail: Running instance of a job (IMAO, It’s overdesign) . For a single HelloJob class, you can create a JobDetail based on it called `fooJobDetail` and another called `barJobDetail`, each has its own Job Data Map and its own JobKey
  • DisallowConcurrentExecution: If it is set up on HelloJob class, then only one process of "fooJobDetail" can be run at the same time; But you can run `barJobDetail` at the same time.

Persistence

  • JDBC-JobStore: Not only job, but schedulers/triggers/jdbcDataMap can be saved into database. You can use jdbc configurations as well as dataSource

Clustering

  • Single-node firing: With Jbdc-JobStore you can make sure only one node will fire the job for each firing. All you need to do is to set `org.quartz.jobStore.isClustered = true`
  • Fail-over: fail-over can also be done if `org.quartz.jobStore.isClustered = true` and the JobDetail`s `request recovery` flag is set to true).

Things that can be handy

  • Calendar: If you have trigger that fires everday but not during public holdays, you can use this
  • Job/Trigger/Scheduler Listeners: an interface to let you plugin some callbacks when something is done. Can be handy for monitoring or auditing purposes.

To make things more robust

  • RequestsRecovery: After you recover from a `hard shutdown`, when the scheduler starts again, the job that went away during the hard shutdown will be re-executed. This only applies to persistent jobs.
  • Misfire Instructions: A trigger may not be fired when it should. When a scheduler is started again, it will find out all misfired trigger to do something, such as MISFIRE_INSTRUCTION_FIRE_NOW or MISFIRE_INSTRUCTION_DO_NOTHING. This only applies to persistent triggers.

Customization

  • DirectSchedulerFactory: with this you don’t have to use quartz.properties but rather configure them in a programatic way

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.