Quartz Second Class Jobs and Triggers (Official document translator)

Source: Internet
Author: User

The Quartz API
    1. ischeduler-the main interface of interaction with scheduler
    2. Ijob-This interface primarily defines scheduler execution content
    3. Ijobdetail-for defining a jobs instance
    4. itrigger-Define Scheduler How to perform the job
    5. jobbuilder– is used to define the build jobdetail strength, which is defined as the instance of jobs
    6. triggerbuilder-for defining and building trigger instances

For better readability, the following terms are used interchangeably: IScheduler and Scheduler, IJob and Job, Ijobdetail and Jobdetail, Itrigger and Trigger.

The life cycle of the scheduler is the end from the time it was created, through schedulerfactory , to the call Shutdown (). Once scheduler is created, it is possible to call the Add and remove methods to add and remove jobs and triggers and other scheduling-related operations (such as pausing trigger). If the Start () method is not called, Scheduler does not execute any jobs under any triggers.

Quartz defines a particular language format (called DSL or fluent interface) that has been seen in the previous section to use it so that we can look at it again.

1 //define the job and tie it to our Hellojob class2Ijobdetail job = jobbuilder.create()3. Withidentity ("MyJob","group1")//name "MyJob", Group "group1"4         . Build ();5         6     //Trigger the job to run now, and then every seconds7Itrigger trigger =triggerbuilder.create ()8. Withidentity ("Mytrigger","group1")9         . Startnow ()Ten. Withsimpleschedule (x =x One. Withintervalinseconds ( +) A             . RepeatForever ()) -         . Build (); -          the     //Tell Quartz to schedule the job using our trigger -Sched.schedulejob (Job, Trigger)
View Code

Use Jobbuilder when building the code block for the job, and use fluent INTERFAC to create the interface Ijobdetail. Similarly, build the trigger code block using Triggerbuilder's fluent interface and call the extension method to specify the trigger type. The available time extension methods are:

    • Withcalendarintervalschedule
    • Withcronschedule
    • Withdailytimeintervalschedule
    • Withsimpleschedule

The Datebuilder class contains a variety of methods to facilitate the construction of DateTimeOffset instances. (for example, an even number of hours to change a specific point of time 10:00:00 is currently 9:43:27)

Jobs and Triggers

Job implementation Ijob Interface, there is only one simple method in the interface

IJob Interface

1 namespace Quartz 2     {3public         interface  IJob4        { 5             void Execute (Jobexecutioncontext context); 6         }7 }

When trigger fires, the Scheduler ' thread invokes the Execute () method. The Jobexecutioncontext object provides the job instance as well as the runtime's environment information to be executed by scheduler, and a trigger is triggered for this execution to include Jobdetail objects as well as other items.

When scheduler adds a job, scheduler creates the Jobdetail object. It contains the various property settings of the job as a jobdatamap save, which can be used to store state information as a job instance. It is essentially the definition of job jobs. Details are discussed in the next session.

The trigger object is used to trigger the execution of the job. When you want to perform a job, you instantiate a trigger and ' tune ' whose properties you want to schedule. A trigger may also have a jobdatamap associated with it-this is a trigger-specific postback that passes parameters to the job. Quartz comes with commonly used trigger types, and the most commonly used types are Simpletrigger (Isimpletrigge interface R) and Crontrigger (Icrontrigger interface).

Simpletrigger is the most convenient if you need ' one-time ' execution (the job at a given moment is just a single execution), or if you need to work at a given hour and repeat it n times, delay t execution between. If you want a calendar-like time to trigger Crontrigger is useful-"10th 10:15 each month", "every Friday, noon".

Why should there be jobs and triggers? Many job schedulers do not have the jobs and triggers concept. Some define "job" as simply using some small job identifiers along the execution time (or schedule). Others are like quartz's job and trigger objects collection. In developing quartz, we think it is meaningful to create a separation between the schedule and the work to be performed on this schedule. It's a lot of good to do (in our opinion).

For example, jobs can be created and stored independently in job scheduler, and many triggers can be associated with the same job. Another benefit of this loose coupling is that the configuration stays on the schedule after their associated trigger has expired, so it can be rescheduled later in the job without having to redefine it. It also allows you to modify or replace Tirgger without redefining its associated job.

Identities

Jobs and Tirggers allow the key to be defined in the register to Quartz scheduler. These keys are useful in organizing the management of jobs and tirggers. Jobs and Tiggers with the same group key are included in a group.

Quartz Second Class Jobs and Triggers (Official document translator)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.