您的位置:首页 > 编程语言 > Java开发

Spring Boot 定时任务的使用

2017-08-01 20:13 435 查看
本文介绍在 Spring Boot 中怎样使用定时任务,使用很easy,就不做过多说明了。

以下是代码类:

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 ... ");
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: