欢迎来到代码驿站!

JAVA代码

当前位置:首页 > 软件编程 > JAVA代码

Spring Boot定时任务的使用方法

时间:2021-06-22 09:36:14|栏目:JAVA代码|点击:

本文介绍在Spring Boot 中如何使用定时任务,使用非常简单,就不做过多说明了。

下面是代码类:

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

}

上一篇:springboot 注册服务注册中心(zk)的两种方式详解

栏    目:JAVA代码

下一篇:Java类之间的关系图_动力节点Java学院整理

本文标题:Spring Boot定时任务的使用方法

本文地址:http://www.codeinn.net/misctech/146209.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有