hutool regular tasks

Introduction

    CronUtil by a global timing tasks profiles to achieve a unified timing task scheduling.

use

1, the configuration file

            1.1 pom file

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

1.2

    For the Maven project, first src/main/resources/created under config package, put cron.setting file in the package (this is the default file this path),

Then placed in the file timing rules, rules are as follows:

# Is a comment I 
name a class or object # method where the execution of the package 
[com.web.kds.hadoop_kafka.TimingTask] 
# class and method names need to perform 
cron.test1 = * * / 1 * * *  
cron.test2 = * * / 1 * * *  

# name of the class or object where the method of performing packet 
[com.web.kds.hadoop_kafka.image] 
# class name and method name to be executed 
WaterMarkUtils.test3 = * / 1 * * *

    

[com.web.kds.hadoop_kafka.TimingTask]:

      Brackets indicate the packet also indicates the path approach requires a class or object where the package itself, such an approach is conducive to distinguish between different services of the timing tasks.

 

cron.test1 

   Represents the class name and method name to be executed (invoked by reflection), * / * * * 1 indicates the timing task expression, represented here is performed once per minute, equivalent to the above configuration:

    com.web.kds.hadoop_kafka.TimingTask.cron.test1 = * / 1 * * *

    com.web.kds.hadoop_kafka.TimingTask.cron.test2 =* */1 * * *

      com.web.kds.hadoop_kafka.image.WaterMarkUtils.test3 =* */1 * * * 

2 . Test code

 

 

 

3. Start / Close

 
CronUtil.start();//启动
CronUtil.stop();//关闭


 

 

 

For compatibility Quartz expression, and there is a second level of matching accuracy requirements, Hutool compatibility may be provided by using second matching mode.

//支持秒级别定时任务
CronUtil.setMatchSecond(true);

此时Hutool可以兼容Quartz表达式(5位表达式、6位表达式都兼容/6位精确到秒)

 

 

 

3. Effect

 

 

 

Guess you like

Origin www.cnblogs.com/KdeS/p/11934151.html