5.17 Quartz notes

  Useful to builder mode:

    builder --- JobDetail equivalent parts require a builder constructed out: JobDetail offers many setting properties, as well as member variables JobDetaMap Job instance attribute, which is used to store a particular example of Job state information, the scheduler needs to objects by means JobDeatil Add Job instance! JobDetail important attributes: name \ group \ jobClass \ jobDataMap! ! Group name is not set: DEFAULT!

    builder --- Trigger is equivalent to require builders to build out a fitting

    adapter --- Scheduler and Trigger JobDetail equivalent of two parts assembled into a Scheduler

 

  A --- JobExecutionContext description and JobDataMap [Note: When performing scheduling in the JobExecutionContext JobDataMap storage (Start: Job class is passed to the execute () method)] in

  AA --- Job stateful and stateless Job [@PersisJobDataAfterExecution annotations Use: There can be understood as a state of Job Job several times during the call may hold some state information in the JobDataMap, and the default status information storage stateless job will create a new JobDataMap] each call.

  AAA --- HelloJob plus @PersisJobDataAfterExecution comment count (Method SET) has accumulated state] [-------------- repeated without annotations scheduled start count value is fixed,

  AAAA --- Trigger trigger introduce -SimpleTriggerImpl-CronTriggerImpl [jobKey-startTime-endTime]

  AAAAA --- SimpleTrigger Trigger: SimpleTrigger to set up and use the most simple one is that it requires QuartzTrigger- / start time on a particular date and at a time interval may be repeated n times designed to Job - case one: that in a specified period of time, perform a job task - case 2: perform a job or task multiple times within a specified time period - 3 case: end time specified task

  AAAAAA --- CronTrigger triggers: If you need to schedule triggered by that task as a calendar, rather than SimpleTrigger specific time intervals as the trigger, CronTriggers usually more useful than SimpleTrigger, because it is a calendar-based job scheduler. [There are] startTime-endTime

 

  When each call will generate an instance of Job

 

First, we first need to understand a few core concepts of Quartz.

  A --- Job represents a job, the specific contents to be executed. This interface is only one method as follows: void execute (JobExcutiontext context)

  B --- JobDetail represents a particular executable scheduler! ! , Job content is the scheduler executables to be executed, in addition JobDetail also includes the scheduling of programs and strategies. ! If you override the no-argument constructor within HelloJob, which has system statement, will first perform the constructor with no arguments overridden in the output statement!

  --- C the Trigger on behalf of a scheduling configuration parameter, when to tune.

  --- D Scheduler represents a dispatch container, a container may be registered in a plurality of scheduling JobDetail and Trigger. Trigger JobDetail when combined with, the container may be scheduled Scheduler.

  

 

  1. Add dependence. www.mvmrepository.com represents mvn repository URL: You can rely on search to obtain the jar maven

    1.1 core package: org.quarzt-scheduler (groupId) --- quartz (artifactId)

    1.2 工具 :org.quarzt-scheduler(groupId)  ---  quartz-job(artifactId)

    1.3 log bundle: --- log4j need to introduce log4.j.properties (have content) [method using log4j: org.apache.log4j.ConsoleAppender .FileAppender console output or file output --- log4j.rootLogger = info, s console lose]

    1.4 plugin (maven-compiler-plugin) jdk1.8

  2. Create a quartz.job package to create a class! Job interface to achieve! Rewrite execute (JobExecutionContext) method!

    2.1 execute method to write what you want (timed) execution of sentence

  3. Create a quartz.mian package to create an executable class that is the main thread.

    Within 3.1 main Method: A: a scheduler (Scheduler), acquired from the scheduling instance factory (default: instantiating new StdSchedulerFactory ();)

    3.2 B (name, group name): task instance (JobDetail) // load the task class, help bind and HelloJob complete, requires HelloJob implement Job interface. quarzt

    3.3 C (name, group name): Trigger (Trigger), custom start immediately trigger! Construction simple scheduler (time forever (custom repetition time) is repeated a second time after 5 seconds)!

    3.4 A2: A first create a scheduler that is adapted BC (builder accessories): schduler.scheduleJob (jobDetail, trigger); // let the scheduler and triggers the associated task to ensure the conditions to perform tasks in accordance with the definition of a trigger

    3.5 D: scheduler.start (), the dispatcher calls the start method.

  4. Run: i.e. not HelloJob 5 seconds to perform a class.

 

 

        

Guess you like

Origin www.cnblogs.com/wym591273/p/10926624.html