JFinal实现定时任务调度

maven中引入定时器任务

  <!--引入定时器任务-->
  <dependency>
        <groupId>it.sauronsoftware.cron4j</groupId>
        <artifactId>cron4j</artifactId>
	<version>2.2.5</version>
  </dependency>



然后在继承JFinalConfig中引入相应的配置文件
	/**
	 * 配置插件
	 */
	public void configPlugin(Plugins me) {
		Cron4jPlugin cp = new Cron4jPlugin("task.txt");//直接配置cron4j
		me.add(cp);
	}
然后在resourse中穿件配置文件task.txt

# cron 表达式由五部分组成:分 时 天 月 周
# 分 :从 0 到 59
# 时 :从 0 到 23
# 天 :从 1 到 31,字母 L 可以表示月的最后一天
# 月 :从 1 到 12,可以别名:jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov" and "dec"
# 周 :从 0 到 6,0 表示周日,6 表示周六,可以使用别名: "sun", "mon", "tue", "wed", "thu", "fri" and "sat"
#
# 数字 n:表示一个具体的时间点,例如 5 * * * * 表示 5 分这个时间点时执行
# 逗号 , :表示指定多个数值,例如 3,5 * * * * 表示 3 和 5 分这两个时间点执行
# 减号 -:表示范围,例如 1-3 * * * * 表示 1 分、2 分再到 3 分这三个时间点执行
# 星号 *:表示每一个时间点,例如 * * * * * 表示每分钟执行
# 除号 /:表示指定一个值的增加幅度。例如 n/m表示从 n 开始,每次增加 m 的时间点执行
# cron4j 集成cron 只有 分 时 天 月 周  没有秒

cron4j=test
test.cron=* * * * *
test.class=com.demo.itTask.test
test.daemon=true
test.enable=true
看到上面的class中进行相应的路径进行写类就可以了
package com.demo.itTask;

/**
 * Created by leo on 2018/1/22.
 *
 */
public class test implements Runnable {
    public void run() {
        System.out.println("每分钟执行一次");
    }
}




猜你喜欢

转载自blog.csdn.net/qq_35733535/article/details/79131683