2021-03-15-Using the hutool tool class to implement timing tasks in the project (super simple)

Preface

  • The method of this document is suitable for maven projects, non-maven projects only need to replace the dependencies with jar packages.

pom.xml

     <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-all</artifactId>
            <version>5.5.7</version>
        </dependency>

Two task classes

public class TestJob {


    public void test() {
        System.out.println("执行TestJob的test");
    }
}

public class TestJob2 {


    public void test() {
        System.out.println("执行TestJob2的test");
    }
}

Configuration

  • For the Maven project, first put the cron.setting file under src/main/resources/config (the file in this path by default), and then put the timing rules in the file. The configuration file code is as follows:
# 我是注释
[com.qcl.job]
TestJob.test = */3 * * * * *
TestJob2.test = */10 * * * * *
  • Brackets indicate grouping, and also indicate the name of the package where the class or object method needs to be executed
  • TestJob.test indicates the name of the class and method to be executed

carried out

 public static void main(String[] args) {
        CronUtil.start();
    }
  • The above is executed in main. For example, if it needs to be executed when the project is started, the portal

Guess you like

Origin blog.csdn.net/qq_41270550/article/details/113983874