Quartz

编程入门 行业动态 更新时间:2024-10-24 18:16:03
本文介绍了Quartz - 每两周在一周的几天和时间安排作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要创建工作,它将:

I need to create Job that will :

  • 从 2012 年 12 月 20 日开始
  • 结束日期 = 12/31/2017
  • 将在周日和周一每 2 周发生一次
  • 下午 5 点开火.

这个 cron 表达式有效吗?

is this cron expression valid?

Date start = 12/20/2012; Date endDate = 12/31/2017; SimpleTrigger trigger = newTrigger() .withIdentity("trigger3", "group1") .startAt(startDate) .withSchedule(cronSchedule("* * 17 0 0/2 *,SUN,MON").build()) .endAt(endDate) .build;

请指教.

推荐答案

我建议您根据 cron 表达式进行单元测试.感谢 Van de Voorde Toni,您可以基于此代码,并使用它来验证nextValidTimeAfter"是否符合您的期望:

I suggest, that you make a unit test based on your cron expression. With kudos to Van de Voorde Toni, you can base it on this code, and use it to verify that the "nextValidTimeAfter" matches your expectation:

import java.text.ParseException; import java.util.Date; import org.quartz.CronExpression; public class CronTester { public static void main(String[] args) throws ParseException { final String expression = "* * 17 0 0/2 *,SUN,MON"; final CronExpression cronExpression = new CronExpression(expression); final Date nextValidDate1 = cronExpression.getNextValidTimeAfter(new Date()); final Date nextValidDate2 = cronExpression.getNextValidTimeAfter(nextValidDate1); System.out.println(nextValidDate1); System.out.println(nextValidDate2); } }

更多推荐

Quartz

本文发布于:2023-11-27 05:11:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636738.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Quartz

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!