本文介绍在spring boot 中如何使用 定时任务 ,使用非常简单,就不做过多说明了。
下面是代码类:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
package org.springboot.sample.config;
import org.slf4j.logger; import org.slf4j.loggerfactory; import org.springframework.context.annotation.configuration; import org.springframework.scheduling.annotation.enablescheduling; import org.springframework.scheduling.annotation.scheduled;
/** * 定时任务配置类 * * @author 单红宇(365384722) * @myblog http://blog.csdn.net/catoop/ * @create 2016年3月21日 */ @configuration @enablescheduling // 启用定时任务 public class schedulingconfig {
private final logger logger = loggerfactory.getlogger(getclass());
@scheduled (cron = "0/20 * * * * ?" ) // 每20秒执行一次 public void scheduler() { logger.info( ">>>>>>>>>>>>> scheduled ... " ); }
} |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
查看更多关于Spring Boot定时任务的使用方法的详细内容...