Quartz-jobdetail and Trigger-job_quartz

Source: Internet
Author: User

Quartz is an open source job scheduling framework, written entirely in Java, where you can create simple or complex tasks. He can offer great flexibility without sacrificing simplicity.

Core concepts of Quartz: Scheduler (Scheduler), triggers, jobs (Job)

1, Scheduler (Scheduler)

Scheduler represents a dispatch container in which multiple jobdetail and trigger can be registered. When Trigger and Jobdetail are combined, they can be scheduled by the scheduler container.

Scheduler is responsible for managing quartz's operating environment, quartz it is based on a multithreaded architecture that initializes a set of threads that will be used to perform some preset jobs.

To create a job and be able to trigger the call, a jobdetail and trigger must be registered on the scheduler.

Scheduler all trigger and jobdetail to coordinate their work. These trigger and Jobdetail are distinguished by their own name and group attributes.

Scheduler produced by Schedulerfactory

[Java] View plain copy schedulerfactory factory = new Stdschedulerfactory ();   Scheduler Scheduler = Factory.getscheduler (); 2, Job (Job)

A task that represents the specific content of a job to be executed. is actually an interface. To create a task, you must implement this interface. The interface has only one execute method, and the task executes the logic of the Execute method each time it is invoked.

[Java] View plain copy public class testjob impletemens org.quartz.job{              @Override              public void execute (Jobexecutioncontext context)  throws  jobexecutionexception{                       // you business logic                       //                       system.out.println ("########### this is testjob running  ############");         }  }   3, Jobdetail

Jobdetail represents a specific executable scheduler in which the job is performed by the executable scheduler, and the Jobdetail includes the program and strategy for this Task scheduler. A jobdetail can have multiple trigger, but a trigger can only correspond to one jobdetail. Here are some common properties and implications of Jobdetail

Name of parameter

Type

Note

Name

String

The name of the task that must be

Group

String

The group with the task, defaults to default

Jobclass

Class

The implementation class for the task, which must be

Description

String

Describe

Jobdatamap

Jobdatamap

Data structure used to support the job

Volatility

Boolean

To delete information about a task after restarting the application, default false

Durability

Boolean

If the task is still persisted to the database after it is completed, the default false

Shouldrecover

Boolean

Ignore expiration task after application reboot, default false

Joblisteners

Set

Listener Jobdatamap

This is a data structure to provide data support to the job, and it is very convenient to use the same method as Java.util.Map. When a job is assigned to the scheduler, the Jobdatamap instance is generated.

The job has a statefuljob sub-interface that represents a stateful task, which is a label interface with no methods, and its purpose is to let quartz know the type of task in order to adopt different execution scenarios. Stateless tasks have their own jobdatamap copies at execution time, and changes to Jobdatamap do not affect the next execution. While stateful task sharing shares the same Jobdatamap instance, the changes that are made to jobdatamap each time the task executes are saved, and subsequent execution can see the change, which affects subsequent execution after each execution of the task.

For this reason, stateless jobs can be executed concurrently, and stateful statefuljob cannot be executed concurrently, which means that if the previous statefuljob has not been completed, the next task will block the wait until the previous task has finished executing. Stateful tasks have more factors to consider than stateless tasks, and programs tend to have a higher degree of complexity, so you should try to use stateless jobs unless necessary.

If Quartz uses database persistence task scheduling information, stateless Jobdatamap will only be maintained once while scheduler registers the task, and the jobdatamap of the stateful task will be saved each time the task is executed.

Jobdatamap instances can also be associated with a trigger. In this case, for different triggers for the same job, we can add different data to the Jobdatamap so that the job can provide more flexible data support at different times (the first edition of the school morning Exercise and the second edition in the afternoon).

Whether stateful or stateless, changes made to trigger's jobdatamap during the execution of a task do not persist, nor do they affect the next execution.

4, Trigger

Trigger represents the configuration of a dispatch parameter and when to tune it.

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.