Quartz Calendar objects (notJava.util.Calendar objects) can being associated with triggers at the time of the trigger is de Fined and stored in the scheduler.
Calendars is useful for excluding blocks of time from the trigger ' s firing schedule. For instance, could create a trigger that fires a job every weekday at 9:30am, but then add a Calendar that exclu Des all of the business ' s holidays.
Calendar's can is any serializable object that implements the Calendar interface {shown below).
package Org.quartz;
public interface Calendar { public boolean Istime Included (long TimeStamp); public long Getnextincludedtime (long TimeStamp); }
Notice the parameters to these methods is of the long type. These is timestamps in millisecond format. This means the calendars can ' block out ' sections of time as narrow as a millisecond. Most likely, you'll be interested in ' blocking-out ' entire days. As a convenience, Quartz includes the class Org.quartz.impl.HolidayCalendar, which does just that.
Calendars must is instantiated and registered with the scheduler via the Addcalendar (..) method. If you use the Holidaycalendar, after instantiating it, you should with its addexcludeddate (date Date) method in order To populate it with the "wish to" has excluded from scheduling. The same calendar instance can be used with multiple triggers as shown in the example below:
Holidaycalendar cal =NewHolidaycalendar (); Cal.addexcludeddate (somedate); Cal.addexcludeddate (someotherdate); Sched.addcalendar ("Myholidays", Cal,false); Trigger T=Newtrigger (). Withidentity ("Mytrigger"). Forjob ("MyJob"). Withschedule (Dailyathourandminute (9, 30))//execute job daily at 9:30am. Modifiedbycalendar ("Myholidays")//But not on holidays. Build (); //.. schedule job with TriggerTrigger t2 =Newtrigger (). Withidentity ("MyTrigger2"). Forjob ("MyJob2"). Withschedule (Dailyathourandminute (11, 30))//Execute job daily at. Modifiedbycalendar ("Myholidays")//But not on holidays. Build (); //.. schedule job with Trigger2
The code above creates the triggers, each scheduled to fire daily. However, any of the firings that would has occurred during the period excluded by the calendar would be skipped.
The Org.quartz.impl.calendar package provides a number of calendar implementations, which may suit your needs.
Quartz Scheduler (2.2.1)-Usage of calendars