Getting to Know Quartz-Personal Learning Summary

1. quartz mode

  • Builder mode

  • Factory mode

  • component mode

  • chain programming

2. quartz core

  • Task Job

    Job is the task class you want to implement. Each job must implement the org.quartz.job interface, and only need to implement the execute() method defined by the interface.

  • Trigger Trigger

    Trigger is the trigger for you to execute the task. For example, if you want to send a statistical mailbox at 3 o'clock every day, Trigger will set 3 o'clock to execute the task.

    Trigger mainly includes two types, SimpleTrigger and CronTrigger.

  • SchedulerScheduler

    The Scheduler is the scheduler of the task, which integrates the task job and the trigger Trigger, and is responsible for executing the job based on the Trigger setting time.

3. Quartz architecture

After Scheduler integrates Trigger and Job, it controls start, stop, pause, resume...

4. quartz common API

  • Scheduler is the main program interface used to interact with the scheduler;

    Scheduler scheduler-task execution plan table, only the task job that is scheduled into the execution plan (arranged into the execution plan through the scheduler.schedulerJob method), when its predefined execution time arrives (task trigger Trigger), the task will be executed ;

  • Job is a pre-defined task class that we hope to be scheduled for execution in the future, and we can customize it;

  • JobDetail uses JobDetail to define instances of scheduled tasks, and JobDetail instances are created through the JobBuilder class;

  • JobDataMap can contain unlimited (serialized) data objects, and the data in it can be used when the job instance is executed; JobDataMap is an implementation of the Java Map interface, and some additional methods for accessing data of basic data types are added ;

  • Trigger trigger, the Trigger object is used to trigger the execution of the Job. When scheduling a job, we instantiate a trigger and adjust its properties to meet the conditions for job execution. Indicates when the task will be executed. Defines the time condition when a scheduled task will be executed, for example, every 2 seconds.

  • JobBuilder- used to declare a task instance, you can also define details about the task such as task name, group name, etc., this declared instance will be used as an actual task;

  • TriggerBuilder trigger creator, used to create trigger trigger instance;

  • JobListener, TriggerListener, and SchedulerListener listeners are used to monitor components.

5. The use of quartz

Quartz depends on:

<!-- quartz -->
<dependency>
    <groupId>org.quartz-scheduler</groupId>
    <artifactId>quartz</artifactId>
    <version>2.3.2</version>
</dependency>
<!-- quartz-jobs -->
<dependency>
    <groupId>org.quartz-scheduler</groupId>
    <artifactId>quartz-jobs</artifactId>
    <version>2.3.2</version>
</dependency>

slf4j depends on:

<!-- slf4j -->
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.7.12</version>
</dependency>
<!-- log4j -->
<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
</dependency>

log4j.properties

### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionoPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### direct messages to file mylog.log ###
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=d:/mylog.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionoPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### set log levels - for more verbose logging change 'info' to 'debug' ###

log4j.rootLogger=info, stdout

5.1 quartz-helloworld mode

Create a scheduled task class: HelloJob

package com.zfl19.quartz.job;

import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author 19zfl
 * @date 2023/5/15
 */
@Slf4j
public class HelloJob implements Job {

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        // 输出当前时间
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(date);
        log.info(format);
    }

}

Create a scheduler: HelloScheduler

package com.zfl19.quartz.main;

import com.zfl19.quartz.job.HelloJob;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

/**
 * @author 19zfl
 * @date 2023/5/15
 */

public class HelloScheduler {

    public static void main(String[] args) throws Exception {

        // 调度器(Scheduler),从工厂中获取调度实例
        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
        // 任务实例(JobDetail)
        JobDetail jobDetail = JobBuilder.newJob(HelloJob.class) // 加载任务类,与HelloJob完成绑定,要求重写org.quartz.Job类的execute方法
                .withIdentity("job1", "job-group1") // 参数1:任务的名称(唯一标识),参数2:任务组的名称
                .build();
        // 触发器(Trigger)
        SimpleTrigger trigger = TriggerBuilder.newTrigger()
                .withIdentity("trigger1", "trigger-group1") // 参数1:触发器的名称(唯一标识),参数2:触发器组的名称
                .startNow() // 马上启动
                .withSchedule(SimpleScheduleBuilder.simpleSchedule().repeatSecondlyForever(5))  // 每5秒重复执行一次
                .build();
        // 让调度器关联任务和触发器,保证按照触发器定义的条件执行任务
        scheduler.scheduleJob(jobDetail, trigger);
        // 启动
        scheduler.start();
    }

}

summary:

The HelloWorld pattern requires:

  • Task Job class: the task you need to perform;

  • Scheduler: task scheduler (a tool that allows your job program to run according to the time and other conditions you want):

  • Get the scheduler object (instance) from StdSchedulerFactory;

  • Obtain the task instance from JobBuilder, and complete the binding with the task Job class (the Job class must rewrite the execute method of the org.quartz.Job class;

  • Get the trigger object from TriggerBuilder, and set the trigger time of the task Job class and other information;

  • Let the scheduler instance associate the task instance with the trigger instance to ensure that the task is executed according to the conditions defined by the trigger;

5.2 Introduction to Job and JobDetail

  • Job: Work task scheduling interface, the task class needs to implement this interface. The execute method is defined in this interface, which is similar to the run method of the TimeTask class provided by jdk. Write the business logic code for task execution in it;

  • The life cycle of the Job instance in Quartz: Every time the scheduler executes the Job, it will create a new Job instance before calling the execute method. When the scheduling is completed, the associated Job object instance will be released, and the released instance will be Garbage collection mechanism recycling;

// 当我在任务Job类中创建一个无参构造输出一句话
@Slf4j
public class HelloJob implements Job {

    public HelloJob() {
        System.out.println("任务被触发:");
    }

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        // 输出当前时间
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(date);
        log.info(format);
    }

}

It is enough to prove that after the scheduler executes the task Job class, the instance will be released, and a new instance needs to be recreated for the next execution.

  • JobDetail: JobDetail provides many setting properties for the Job instance, as well as the JobDataMap member variable property, which is used to store the status information of a specific Job instance. The scheduler needs to use the JobDetail object to add the Job instance;

  • Important attributes of JobDetail: name, group, jobClass, jobDataMap

// 任务实例(JobDetail)
        JobDetail jobDetail = JobBuilder.newJob(HelloJob.class) // 加载任务类,与HelloJob完成绑定,要求重写org.quartz.Job类的execute方法
                .withIdentity("job1", "job-group1") // 参数1:任务的名称(唯一标识),参数2:任务组的名称
                .build();
        String group = jobDetail.getKey().getGroup();
        String name = jobDetail.getKey().getName();
        log.info(group);
        log.info(name);

Notice:

  • Obtain the job class name bound to the task instance through jobDetail.getJobClass.getName();

  • When the group name group is not set for the task instance, the default value of quartz will be used: DEFAULT;

  • The task name of the task instance must be specified, because the task name must be specified by default in the withIdentity method

5.3 Introduction to JobExecutionContext

  • When the Scheduler calls a Job, it will pass the JobExecutionContext to the execute() method of the Job;

  • Job can access the Quartz runtime environment and detailed data of the Job itself through the JobExecution object;

@Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        // 获取jobDetail内容
        JobKey jobKey = jobExecutionContext.getJobDetail().getKey();
        String name = jobKey.getName();     // 获取任务实例名称
        String group = jobKey.getGroup();   // 获取任务实例组名称
        log.info(name);
        log.info(group);
        String className = jobExecutionContext.getJobDetail().getJobClass().getName();
        String simpleClassName = jobExecutionContext.getJobDetail().getJobClass().getSimpleName();
        log.info(className);    // 获取任务实例绑定的任务Job类(全限定名形式)
        log.info(simpleClassName);  // 获取任务实例绑定的任务Job类(类名形式)
    }

 

 That is to say: after the task Job class is bound to the task instance JobDetail in the scheduler, the information of the task instance can be obtained through the JobExecutionContext object in the execute method of the org.quartz.Job class, of course, the scheduling can be obtained in the task Job class The trigger instance Trigger information in the trigger is also consistent with the task instance JobDetail obtained

5.4 Introduction to JobDataMap

(1) Use Map to get

  • During task scheduling, JobDataMap is stored in JobExecutionContext, which is very convenient to obtain;

  • JobDataMap can be used to load any data object that can be serialized. When the Job instance object is executed, these objects will be passed to him;

  • JobDataMap implements the Map interface of jdk, and adds very convenient methods to access basic data types;

Now there is a requirement, I need to obtain the data stored in the JobDataMap in the scheduler in the task Job class :

HelloScheduler.java

@Slf4j
public class HelloScheduler {

    public static void main(String[] args) throws Exception {
        // 调度器(Scheduler),从工厂中获取调度实例
        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
        // 任务实例(JobDetail)
        JobDetail jobDetail = JobBuilder.newJob(HelloJob.class) // 加载任务类,与HelloJob完成绑定,要求重写org.quartz.Job类的execute方法
                .withIdentity("job1", "job-group1") // 参数1:任务的名称(唯一标识),参数2:任务组的名称
                .usingJobData("message", "data01")
                .build();
        // 触发器(Trigger)
        SimpleTrigger trigger = TriggerBuilder.newTrigger()
                .withIdentity("trigger1", "trigger-group1") // 参数1:触发器的名称(唯一标识),参数2:触发器组的名称
                .usingJobData("message", "data02")
                .startNow() // 马上启动
          .withSchedule(SimpleScheduleBuilder.simpleSchedule().repeatSecondlyForever(5))  // 每5秒重复执行一次
                .build();
        // 让调度器关联任务和触发器,保证按照触发器定义的条件执行任务
        scheduler.scheduleJob(jobDetail, trigger);
        // 启动
        scheduler.start();
    }

It can be seen that both the task instance and the trigger instance in the scheduler store a data whose key is message and value is data. How to get the value in the task Job class?

HelloJob.java

@Slf4j
public class HelloJob implements Job {
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        // 获取JobDataMap信息
        String messageByJobDetail = jobExecutionContext.getJobDetail().getJobDataMap().getString("message");
        String messageByTrigger = jobExecutionContext.getTrigger().getJobDataMap().getString("message");
        log.info(messageByJobDetail);
        log.info(messageByTrigger);
        // 输出当前时间
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(date);
        log.info(format);
    }

Common methods:

  • Get the execution time of the current task Job class

@Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        // 获取当前Job的执行时间
        Date fireTime = jobExecutionContext.getFireTime();
        SimpleDateFormat simpleDateFormatJob = new SimpleDateFormat();
        String formatDate = simpleDateFormatJob.format(fireTime);
        log.info(formatDate);
    }
  • Get the execution time of the next task Job class
@Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        // 获取下次任务Job类的执行时间
        Date nextFireTime = jobExecutionContext.getNextFireTime();
        SimpleDateFormat simpleDateFormatJob = new SimpleDateFormat();
        String formatDate = simpleDateFormatJob.format(nextFireTime);
        log.info(formatDate);
    }

(2) Add setter methods corresponding to JobDataMap in the Job implementation class. The default JobFactory implementation class of the Quartz framework will automatically call these class setter methods when initializing the Job instance object.

Declare a String-type field in the task Job class. The key stored in the task instance object and trigger instance object before is message, so declare a String-type field message in the task class and provide a setter method;

Notice:

If a key with the same name is encountered, .usingJobData("message", "data01") in Trigger will overwrite .usingJobData("message", "data01"); in JobDetail;

5.5 Stateful Job and Stateless Job

Use of @PersistJobDataAfterExecution annotation

A stateful Job can be understood as holding some state information during multiple Job calls, which are stored in the JobDataMap, while the default stateless Job creates a new JobDataMap each time it is called.

The job class declared in quartz is stateless by default, and a new instance will be created every time the execution is called, and it will be recovered after execution;

HelloJob.java

@Slf4j
public class HelloJob implements Job {

    private Integer count;

    public void setCount(Integer count) {
        this.count = count;
    }

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {

        ++count;
        log.info(count.toString());

        jobExecutionContext.getJobDetail().getJobDataMap().put("count", count);
    }

}

The output is:

After annotating the HelloJob class:  

There is no annotation @PersisitJobDataAfterExecution added to the HelloJob class, and a new JobDataMap will be created every time it is called. will not accumulate;

After the @PersisitJobDataAfterExecution annotation is added to the HelloJob class, some state information can be held during the multiple calls to the Job, that is, the count accumulation operation can be realized.

5.6 Introduction to Trigger

Get the Tirgger instance through TriggerBuilder

Trigger:

  • AbsolutelyTrigger

    • DailyTimeIntervalTriggerImpl

    • CalendarIntervalTriggerImpl

    • SimpleTriggerImpl

    • CronTriggerImpl

Quartz has a few different trigger types, however, the most used are SimpleTrigger and CronTrigger

(1)jobKey

Indicates the identity of the job instance. When the trigger is triggered, the specified job instance will be executed;

(2)startTime

Indicates the schedule of the trigger, the time when it is first triggered, and its data type is java.util.Date;

(3)endTime

Specifies the time when the trigger terminates being triggered, and its data type is java.util.Date;

JobSimpleTrigger.java

@PersistJobDataAfterExecution
@Slf4j
public class JobSimpleTrigger implements Job {

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        // 输出当前时间
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(date);
        log.info("now time : " + format);
    }

}

JobSchedulerTrigger.java

@Slf4j
public class JobSchedulerTrigger {

    public static void main(String[] args) throws Exception {

        // 调度器(Scheduler),从工厂中获取调度实例
        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
        // 任务实例(JobDetail)
        JobDetail jobDetail = JobBuilder.newJob(JobSimpleTrigger.class) // 加载任务类,与HelloJob完成绑定,要求重写org.quartz.Job类的execute方法
                .withIdentity("job1", "job-group1") // 参数1:任务的名称(唯一标识),参数2:任务组的名称
                .usingJobData("message", "data01")
                .build();

        // 触发器(Trigger)
        Trigger trigger = TriggerBuilder.newTrigger()
                .withIdentity("trigger1", "trigger-group1") // 参数1:触发器的名称(唯一标识),参数2:触发器组的名称
//                .startNow() // 马上启动
                .build();
        // 让调度器关联任务和触发器,保证按照触发器定义的条件执行任务
        scheduler.scheduleJob(jobDetail, trigger);
        // 启动
        scheduler.start();
    }

}

It should be noted that if the time loop condition is not specified, the task class Job will only be executed once if the startNow() method is used. If we want to get the startTime and endTime of the Trigger instance in the task Job class, a null pointer will appear Abnormal , at this time we need to configure the following: (do not need to execute immediately, but we set the start and end time ourselves)

JobSchedulerTrigger.java

@Slf4j
public class JobSchedulerTrigger {

    public static void main(String[] args) throws Exception {

        // 调度器(Scheduler),从工厂中获取调度实例
        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
        Date startDate = new Date(); // 开始执行时间
        Date endDate = new Date(); // 结束执行时间
        endDate.setTime(endDate.getTime() + 10000); // 开始执行时间10秒后结束
        // 任务实例(JobDetail)
        JobDetail jobDetail = JobBuilder.newJob(JobSimpleTrigger.class) // 加载任务类,与HelloJob完成绑定,要求重写org.quartz.Job类的execute方法
                .withIdentity("job1", "job-group1") // 参数1:任务的名称(唯一标识),参数2:任务组的名称
                .usingJobData("message", "data01")
                .build();

        // 触发器(Trigger)
        Trigger trigger = TriggerBuilder.newTrigger()
                .withIdentity("trigger1", "trigger-group1") // 参数1:触发器的名称(唯一标识),参数2:触发器组的名称
//                .startNow() // 马上启动
                .withSchedule(SimpleScheduleBuilder.simpleSchedule().repeatSecondlyForever(5))
                .startAt(startDate)
                .endAt(endDate)
                .build();
        // 让调度器关联任务和触发器,保证按照触发器定义的条件执行任务
        scheduler.scheduleJob(jobDetail, trigger);
        // 启动
        scheduler.start();
    }

}

Detailed description: It can be seen from the execution output that we set the execution to repeat every 5 seconds, because we set the start and end execution time of the trigger within 10 seconds, so the number of executions of the task Job class is 2 times.

5.7 SimpleTrigger trigger

SimplTrigger is the easiest QuartzTrigger to set up and use.

It is designed for jobs that need to be started at a specific date/time and repeated n times at a possible interval.

Case 1: Indicates that a task is executed within a specific period of time:

Case 2: Execute a task multiple times within a specified time interval:

Case 3: Specify task execution time:

requires attention:

  • The properties of SimpleTrigger are: start time, end time, number of repetitions and interval of repetitions;

  • The value of the repeat count property can be 0, a positive integer, or the constant SimpleTrigger.REPEAT_INDEFINITELY.

  • The property value of the repeating time interval must be 0 or a positive long integer in milliseconds. When the repeating time interval is 0, it means that it will be executed at the same time as the Trigger.

  • If there is a specified end time attribute value, the end time attribute takes precedence over the number of repetitions attribute. The advantage of this is that when we need to create a Trigger that triggers every 10 seconds until the specified end time, there is no need to calculate the time from the beginning to the end. The number of repetitions at the end, we only need to simply specify the end time and use REPEAT_INDEFINITELY as the attribute value of the number of repetitions;

5.8 CronTrigger trigger

CronTrigger is a calendar based job scheduler

(1) Cron Expressions - Cron expression

Cron expressions are used to configure CronTrigger instances. A Cron expression is a string of 7 subexpressions. Each subexpression describes a single schedule detail. These subexpressions are separated by spaces and represent:

  • Seconds: seconds

  • Minutes: minutes

  • Hours: hours

  • Day-of-Month: day of the month

  • Month: month

  • Day-of-Week: day of the week

  • Year(optional field): Year (optional field)

Value:

field Is it required? allowance special characters to run
Second yes 0-59 ,- * /
point yes 0-59 ,- * /
Hour yes 0-23 ,- * /
Day yes 1-31 ,- * / ?L W C
moon yes 1-12 or JAN-DEC ,- * /
week yes 1-7 or SUN-SAT ,-*/?LC#
Year no Leave blank, or 1970-2099 ,- * /

hint:

  • "L" and "W" can be used together. (Enterprises can be used in salary calculation)

  • "#" can represent the first few weeks of the month. (It can be used to calculate Mother's Day and Father's Day in enterprises)

  • English letters in the week field are not case-sensitive, for example: MON = mon.

  • Use tools to generate online.

5.9 Configuration, Resource SchedulerFactory

Quartz is architected in a modular fashion, so, to make it work, several components must snap together nicely. Fortunately, there are already some helpers that exist that can do this.

All Scheduler instances are created by SchedulerFactory

The three core concepts of Quartz: scheduler, task, trigger, the relationship between the three is:

 

For a job, the more important ones are Scheduler, jobDetail, and Trigger;

It is like a driver for a job, there is no trigger to drive the job regularly. The job cannot run; for a Job, a job can correspond to multiple Triggers, but for a Trigger, a Trigger can only correspond to one Job, so a Trigger can only be assigned to one Job; if you need a more complex Trigger plan, you can create multiple Triggers and assign them to the same Job.

How the Scheduler is created:

(1)StdSchedulerFactoru:

Quartz default SchedulerFactory

  • Use a set of parameters (java.util.Properties) to create and initialize the Quartz scheduler

  • Configuration parameters are generally stored in the quartz.properties file

  • The scheduler object can be created and initialized by calling the getScheduler method

StdSchedulerFactory stdSchedulerFactory = new StdSchedulerFactory();
Scheduler scheduler = stdSchedulerFactory.getScheduler();

Usage 1: output scheduler start time (important: make tasks and triggers associated)

Date date = scheduler.scheduleJob(jobDetail, trigger);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat();
String format = simpleDateFormat.format(date);
log.info(format);

Usage 2: Start task scheduling

scheduler.start();

Usage 3: task scheduling is suspended, task is suspended

        // 执行两秒后自动挂起
        Thread.sleep(2000L);
        // 挂起
        scheduler.standby();
        // 执行5秒后自动开启
        Thread.sleep(5000L);
        // 启动
        scheduler.start();

Usage 4: Turn off task scheduling

shutdown()

shutdown(true): Indicates to wait for all executing Jobs to complete before closing the Scheduler;

shutdown(false): means to close the Scheduler directly

(2) DirectSchedulerFactory (understand):

DirectSchedulerFactory is a direct implementation of SchedulerFactory, through which you can directly build Schedulee, thread pool, etc.;

DirectSchedulerFactory instance = DirectSchedulerFactory.getInstance();
Scheduler scheduler = instance.getScheduler();

5.10 Quartz.properties

Default path: quartz.properties in org.quartz in quartz-2.3.0

We will copy a new file with the same name quartz.properties in the resource folder and change the configuration: org.quartz.threadPool.threadCount: -1

Running the task scheduler again will report an error:

You can know that if we have a file with the same name in the resource resource folder, quartz will use the configuration file under the resource folder by default.

For more configuration information, please refer to: Quartz.properties Configuration File Detailed Explanation_Born out, I raised it! Blog-CSDN Blog

Temporary configuration using a configuration factory

QuartzProperties.java

public class QuartzProperties {

    // 使用java程序修改quartz.properties配置信息
    public static void main(String[] args) {

        // 创建工厂实例
        StdSchedulerFactory stdSchedulerFactory = new StdSchedulerFactory();
        // 创建配置工厂的属性对象
        Properties props = new Properties();
        props.put(StdSchedulerFactory.PROP_THREAD_POOL_CLASS, "org.quartz.simpl.SimpleThreadPool");
        props.put("org.quartz.threadPool.threadCount", "-1");   // 修改线程数,规则是不少于0,启动报错说明修改成功
        // 使用定义的属性初始化工厂
        try {
            stdSchedulerFactory.initialize(props);
            Scheduler scheduler = stdSchedulerFactory.getScheduler();
            scheduler.start();
        } catch (SchedulerException e) {
            throw new RuntimeException(e);
        }

    }

}

If there is no accident, it will report an error as shown in the figure:

This shows that it is effective for us to temporarily configure the quartz.properties file through the configuration factory.

5.11 Quartz listeners

(1) Concept

The listener of Quartz is used to get the notification of this event in time when the event you are concerned about occurs in the task setting. It is similar to the email and text message reminders during the execution of personal affairs. Quartz listeners mainly include JobListener, TriggerListener, and SchedulerListener. As the name suggests, they represent the listeners corresponding to tasks, triggers, and schedulers, respectively. The use of the three is similar. Before introducing the three listeners, two concepts need to be clarified: global listeners and non-global listeners. The difference between the two is: the global listener can receive all job/Trigger event notifications , the non-global listener can only receive the events of the job or Trigger registered on it, and the job or Trigger not registered on it will not listen.

(2)JobListener

During the task scheduling process, the events related to the task Job include: the reminder that the Job starts to be executed; the reminder that the Job execution is completed;

 To be edited~

demo reference: GitHub - 19zfl/quartz-demo: basic use of quartz, personal learning summary

Guess you like

Origin blog.csdn.net/m0_53692627/article/details/130714310