JFinal的任务调度cron4jPlugin源码

本文档详细介绍了JFinal插件Cron4jPlugin的源码,它是基于cron4j实现的任务调度器。Cron4jPlugin允许通过配置文件或Java代码来定义任务,使用cron表达式来调度任务执行。它支持Runnable、Task和ProcessTask类型的任务,提供了添加任务、启动和停止调度的方法。此外,还展示了如何通过ProcessTask调用系统程序。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/**
 * Copyright (c) 2011-2016, James Zhan 詹波 (jfinal@126.com).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
package com.jfinal.plugin.cron4j;
 
import it.sauronsoftware.cron4j.ProcessTask;
import it.sauronsoftware.cron4j.Scheduler;
import java.util.ArrayList;
import java.util.List;
import com.jfinal.kit.Prop;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.IPlugin;
import it.sauronsoftware.cron4j.Task;
 
/**
 * Cron4jPlugin 封装 cron4j,使用 cron 表达式调试 Task 执行
 *
 * 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 的时间点执行
 *
 * 一、配置文件用法
 * cp = new Cron4jPlugin("cron4j.txt");
 * me.add(cp);
 *
 * 配置文件:
 * cron4j=task1, task2
 * task1.cron=* * * * *
 * task1.class=com.xxx.TaskAaa
 * task1.daemon=true
 * task1.enable=true
 *
 * task2.cron=* * * * *
 * task2.class=com.xxx.TaskBbb
 * task2.daemon=true
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值