轻量级任务调度框架sundial

无需复杂的配置,通过实现抽象类org.knowm.sundial.Job,配置注解或者通过xml定义即可轻松使用cron表达式或轮询表达式完成定时任务

A Lightweight Job Scheduling Framework for Java. Sundial makes adding scheduled jobs to your Java application a walk in the park. Simply define jobs, define triggers, and start the Sundial scheduler.

依赖

<dependency>
	<groupId>org.knowm</groupId>
	<artifactId>sundial</artifactId>
	<version>2.2.0</version>
</dependency>

定义job

@CronTrigger(cron = "0/5 * * * * ?")
public class JobTest extends org.knowm.sundial.Job {

    @Override
    public void doRun() throws JobInterruptException {
        // Do something interesting...
        System.out.println("Do something interesting...");
    }
    public static void main(String[] args) {
        String currentPackage = JobTest.class.getPackage().getName();
        String parentPackage = currentPackage.substring(0, currentPackage.lastIndexOf("."));
        SundialJobScheduler.startScheduler(parentPackage);
    }
}

简单配置而不是使用cron表达式

@SimpleTrigger(repeatInterval = 30, timeUnit = TimeUnit.SECONDS)

除了定义包扫描也可手动添加

SundialJobScheduler.addJob("JobTest", "com.xxx.JobTest");

更多文档

  1. github-Sundial