Quartz Study of Jobs and Triggers

Source: Internet
Author: User

A task is a class that implements the job interface. As shown below, there is only one method for the job interface.

Package Org.quartz;    Public interface Job {public      void execute (jobexecutioncontext context)        throws jobexecutionexception;    }

When a Job trigger is triggered, the scheduler takes a thread from the pool of threads to invoke execute (..) Method. The Jobexecutioncontext method has a parameter that can be used to obtain information about the job runtime, such as the scheduler performing one of its processing, the job's Jobdetail object, and so on.

When the Quartz client adds the job to the scheduler, the Jobdetail instance is created. This object has a variety of properties that are used to configure the job. There is also a jobdatamap that holds state information for instances of the job class. The Jobdetail object can construct a Job instance.

The Trigger object can trigger the execution of the job. When you want to schedule a job, you need to initialize a trigger object and set the properties you need based on your needs.

Trigger also has jobdatamap, trigger is triggered, jobdatamap can be a good pass parameter to the job. Quartz provides some useful trigger types, but the most common types of triggers are Simpletrigger and Crontrigger.

    • Simpletrigger: If you need to do it at some point in time, or you need to do it at some point in time (n times ).
    • Crontrigger: If you imagine the time schedule on the calendar to execute, for example, every morning at 5 o ' Day.

Why are Jobs and Triggers? Many task schedulers do not separate the concepts of jobs and Triggers. Some schedulers simply use the job as an execution time, as well as some small job identities. Other schedulers confuse the concept of Jobs and Triggers. Quartz's design separates the execution plan from the specific business work. It's going to be fine.

As an example, you can create a job and save it in the job scheduler. In this case, you can associate the job with many Trigger. One benefit of the exception is the realization of understanding decoupling.

Quartz Study of Jobs and Triggers

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.