zoukankan      html  css  js  c++  java
  • spring 实现定时任务

    spring实现定时任务超级简单。比使用quartz简单,比使用timer强大。如下是一个简单的springboot任务,启用了定时任务

    @SpringBootApplication
    @ComponentScan
    @EnableScheduling //这里添加注解
    public class Application implements CommandLineRunner { // 后台应用,非web,实现CommandLineRunner

    public static void main(String[] args) throws Exception {
    SpringApplication.run(Application.class, args);
    }

    @Override
    public void run(String... args) throws Exception {

    start();

    }

    // cron 秒 分 时 日 月 周几
    //@Scheduled(cron = "0 0 0 * * 6") //每周六执行一次
    @Scheduled(fixedRate = 3000) //每隔3秒执行一次、此注解只能用在无参的方法上。
    private void start(){
    System.out.println("xxx");

    }

    }
  • 相关阅读:
    linux磁盘扩容脚本不重启
    编译安装redis
    编译安装nginx
    ansible常用模块
    centos7 yum安装ansible
    centos7 salt操作命令
    centos7 yum安装salt
    keep
    MySQL6
    MySQL5
  • 原文地址:https://www.cnblogs.com/fsqsec/p/8572152.html
Copyright © 2011-2022 走看看