jobrunr
jobrunr 是一款Distributed and backed by persistent storage定时任务框架。相比于spring task schedule 可以支持分式运行。底层存储可以基于db,redis,es,nosql
基本使用
implementation 'org.jobrunr:jobrunr-spring-boot-3-starter:6.3.4'
定时任务
- 注解方式
@Recurring(id = "my-recurring-job", cron = "*/5 * * * * *")
@Job(name = "My recurring job")
public void doRecurringJob() {
log.info("Doing some work without arguments");
}
- 编程方式。注入
private final JobScheduler jobScheduler;
final JobId scheduledJobId = jobScheduler.schedule(now().plus(Duration.parse(when)), () -> myService.doSimpleJob(value));
说明
- org.jobrunr.server.BackgroundJobServer#startZooKeepers 负责定时轮训storage 层的定时任务。放入到队列中排队执行
- 定时任务目前间隔不能小于
PollIntervalInSeconds,否则会报错。 - 适用场景: 大于30分钟以上的定时任务间隔,不适合调度时间很短的间隔
- 相比其他框架比较轻量,可以作为替换spring task 等定时框架的选择