服务器之家

服务器之家 > 正文

Spring Boot定时任务的使用方法

时间:2021-05-25 13:08     来源/作者:Java之家

本文介绍在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 ... ");
  }
 
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

相关文章

热门资讯

2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
yue是什么意思 网络流行语yue了是什么梗
yue是什么意思 网络流行语yue了是什么梗 2020-10-11
背刺什么意思 网络词语背刺是什么梗
背刺什么意思 网络词语背刺是什么梗 2020-05-22
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总 2020-11-13
2021德云社封箱演出完整版 2021年德云社封箱演出在线看
2021德云社封箱演出完整版 2021年德云社封箱演出在线看 2021-03-15
返回顶部