Quartz Scheduler (2.2.1)-Usage of calendars

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.