Quartz - schedule jobs every two Weeks on several Day of week and time

前端 未结 1 1598
自闭症患者
自闭症患者 2020-12-06 07:28

I need to create Job that will :

  • starts one 12/20/2012
  • endDate = 12/31/2017
  • will occur every 2 weeks on Sunday and monday
  • fires at 5
相关标签:
1条回答
  • 2020-12-06 07:53

    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);
    
        }
    }
    
    0 讨论(0)
提交回复
热议问题