Quartz is a richly featured, open source job scheduling library that can be integrated within virtually any Java application - from the smallest stand-alone application to the largest e-commerce system.


maven 引入


建立 Task

package com.ryo.quartz.hello.job;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

public class MyJob implements Job {

    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        System.err.println("Hello Quartz!");



import com.ryo.quartz.hello.job.MyJob;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

public class AppMain {

    public static void main(String[] args) throws SchedulerException {
        // define the job and tie it to our MyJob class
        JobDetail job = JobBuilder.newJob(MyJob.class)
                .withIdentity("job1", "group1")

        // Trigger the job to run now, and then repeat every 5 seconds
        Trigger trigger = TriggerBuilder.newTrigger()
                .withIdentity("trigger1", "group1")

        // Grab the Scheduler instance from the Factory
        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
        // and start it off
        // Tell quartz to schedule the job using our trigger
        scheduler.scheduleJob(job, trigger);


每 5S 执行一次我们的 Job

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

Hello Quartz!
Hello Quartz!
Hello Quartz!
Hello Quartz!


Quartz 入门系列教程-00-序章