当前位置: 移动技术网 > IT编程>开发语言>Java > (入门SpringBoot)SpringBoot结合定时任务task(十)

(入门SpringBoot)SpringBoot结合定时任务task(十)

2019年05月28日  | 移动技术网IT编程  | 我要评论

springboot整合定时任务task

  1. 使用注解enablescheduling在启动类上.
  2. 定义@component作为组件被容器扫描.
  3. 表达式生成地址:http://cron.qqe2.com

下面是例子:

1.  //开启定时任务:
@enablescheduling
public class demoapplication {

2./**
 * 定时任务:
 */
@component
public class testtask {

    private static final simpledateformat dataformat = new simpledateformat("hh:mm:ss");
    //定义每3秒执行任务:
    @scheduled(fixedrate = 3000)
    public void reportcurrenttime(){
        system.out.println("现在时间:" + dataformat.format(new date()));
    }
}

3.启动就完事了.

提示: 定时任务可以用cron表达式:@scheduled(cron = "")

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网