JFinal极简任务调度插件 jfinal-scheduler

码农软件 · 软件分类 · 作业/任务调度 · 2019-09-04 17:42:13

软件介绍

jfinal-scheduler 是一个基于cron4j以及ScheduledThreadPoolExecutor实现的极简的任务调度插件。

极简体现在几个方便:

1)自动根据CPU内核数设定调度线程数
2)任务只需实现Runnable接口
3)只支持cron表达式(最小单位分钟)/固定频率(时间单位固定为秒)/固定延迟(时间单位固定为秒)4)支持通过配置文件启动任务。插件只需一行代码加载。

如何配置(完全编程配置):

//初始化一个任务调度插件
SchedulerPlugin sp = new SchedulerPlugin();
//初始化一个任务对象(只需实现Runnable接口即可)
Runnable task = new TestTask();
//每隔10秒(固定延迟,相当于串行执行)执行一次
//sp.fixedDelaySchedule(task, 10);
//每隔10秒(固定频率,频率高时相当于并行执行)执行一次
//sp.fixedRateSchedule(task, 10);
//每隔1分钟执行一次
sp.cronSchedule(task, "* * * * *");
//添加插件
me.add(sp);


如何配置(配置文件方式):
//初始化一个任务调度插件,参数为配置文件名
SchedulerPlugin sp = new SchedulerPlugin("job.properties");
//添加插件
me.add(sp);


job.properties配置文件内容:
#是否启用该任务
testJob.enable=true
#任务类名
testJob.class=com.wellbole.web.core.TestTask
#任务类型以及表达式
#testJob.type=cron
#testJob.expr=* * * * *

#每隔10秒(定频率,每分钟6次)执行一次
testJob.type=fixedRate
testJob.expr=10

#每隔5秒(定延迟,任务一个接着一个)执行一次
#testJob.type=fixedDelay
#testJob.expr=5

#job1.class=x.y.z.Runnable
#jobTest.class=x.y.testRunnbale

一般情况下若需要在部署时改变配置,建议使用配置文件配置。

本文地址:https://codercto.com/soft/d/13875.html

Hello World

Hello World

Hannah Fry / W. W. Norton Company / 2018-9 / GBP 17.99

A look inside the algorithms that are shaping our lives and the dilemmas they bring with them. If you were accused of a crime, who would you rather decide your sentence—a mathematically consistent ......一起来看看 《Hello World》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换