Making a sample program to output all firing times between two dates is rather simple :
import java.text.ParseException; import java.util.List; import org.quartz.CronTrigger; import org.quartz.Trigger; import org.quartz.TriggerUtils; import org.quartz.impl.calendar.AnnualCalendar; public class ConfirmTriggerFireTimes { public static void main(String[] args) throws ParseException { new ConfirmTriggerFireTimes().showTriggerFireTimes(); } public void showTriggerFireTimes() throws ParseException { CronTrigger trigger = new CronTrigger(); // Fire at 10:15am every Monday, Tuesday, Wednesday, and Thursday trigger.setCronExpression("0 15 10 ? * MON-THU"); java.util.Calendar startDate = java.util.Calendar.getInstance(); startDate.set(2011,java.util.Calendar.JANUARY, 1); java.util.Calendar endDate = java.util.Calendar.getInstance(); endDate.set(2011,java.util.Calendar.JANUARY, 31); outputFireTimeList(trigger, startDate, endDate); } @SuppressWarnings("rawtypes") private void outputFireTimeList(Trigger trigger, java.util.Calendar from, java.util.Calendar to) { List fireTimeList = TriggerUtils.computeFireTimesBetween(trigger, null, from.getTime(), to.getTime()); for ( int i = 0; i < fireTimeList.size(); i++ ) { System.out.println(fireTimeList.get(i)); } } }In this example, I want to confirm the firing dates of a trigger set to fire at 10:15am every Monday, Tuesday, Wednesday, and Thursday in January. The resulting output is :
Mon Jan 03 10:15:00 JST 2011 Tue Jan 04 10:15:00 JST 2011 Wed Jan 05 10:15:00 JST 2011 Thu Jan 06 10:15:00 JST 2011 Mon Jan 10 10:15:00 JST 2011 Tue Jan 11 10:15:00 JST 2011 Wed Jan 12 10:15:00 JST 2011 Thu Jan 13 10:15:00 JST 2011 Mon Jan 17 10:15:00 JST 2011 Tue Jan 18 10:15:00 JST 2011 Wed Jan 19 10:15:00 JST 2011 Thu Jan 20 10:15:00 JST 2011 Mon Jan 24 10:15:00 JST 2011 Tue Jan 25 10:15:00 JST 2011 Wed Jan 26 10:15:00 JST 2011 Thu Jan 27 10:15:00 JST 2011 Mon Jan 31 10:15:00 JST 2011This looks good. We can see that any jobs associated to this trigger will be executed at 10:15am every Monday, Tuesday, Wednesday, and Thursday.
Bài post của tác giả rất hay, thank bạn đã share.
ReplyDeleteXem tại website : Đá thạch anh vụn
Bài post của Bạn cũng hữu ích, cám ơn anh đã chia sẻ.
ReplyDeleteThông tin thêm : Tỳ hưu thạch anh