2019独角兽企业重金招聘Python工程师标准>>>
1、Spring对quartz支持
2、实例(按红色部分配置)
1)引入quartz包
2)spring-quartz.xml配置
3)QuartzTask类
package com.company.quartz;import org.slf4j.Logger;
import org.slf4j.LoggerFactory;import java.text.SimpleDateFormat;
import java.util.Date;/*** Created by wsy on 2016/11/18.*/
public class QuartzTask {private static final Logger LOG= LoggerFactory.getLogger(QuartzTask.class);public void run(){SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");LOG.info("系统调度时间:"+sdf.format(new Date()));}
}
4)运行结果
2016-11-21 09:41:20.001 [ org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-3 ] - [ INFO ] [ com.company.quartz.QuartzTask : 17 ] - 系统调度时间:2016-11-21 09:41:20
2016-11-21 09:41:30.000 [ org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-4 ] - [ INFO ] [ com.company.quartz.QuartzTask : 17 ] - 系统调度时间:2016-11-21 09:41:30
2016-11-21 09:41:40.001 [ org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-5 ] - [ INFO ] [ com.company.quartz.QuartzTask : 17 ] - 系统调度时间:2016-11-21 09:41:40
2016-11-21 09:41:50.001 [ org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-6 ] - [ INFO ] [ com.company.quartz.QuartzTask : 17 ] - 系统调度时间:2016-11-21 09:41:50
2016-11-21 09:42:00.002 [ org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-7 ] - [ INFO ] [ com.company.quartz.QuartzTask : 17 ] - 系统调度时间:2016-11-21 09:42:00
2016-11-21 09:42:10.000 [ org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-8 ] - [ INFO ] [ com.company.quartz.QuartzTask : 17 ] - 系统调度时间:2016-11-21 09:42:10
2016-11-21 09:42:20.002 [ org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-9 ] - [ INFO ] [ com.company.quartz.QuartzTask : 17 ] - 系统调度时间:2016-11-21 09:42:20
https://github.com/BAN-WANG/demo