In this section we will try to provide the brief description of triggers. As we know that the trigger objects are used for executing the jobs or firing jobs. When we wish to schedule the jobs, then we can used the properties of triggers. Here we are going to provide two types of triggers like: Simple Trigger and Cron Trigger for scheduling the jobs.
Now, we will see how to use these triggers with the Calendar interface.
Quartz Calendars (not java.util.Calendar) objects can be associated with triggers object at the time of the triggers are stored in the scheduler. It is very useful to excluding blocks of time to fire the triggers schedule. For example, we wish to create a trigger that fires a job every weekday at 4.15 am, in this case we would to add a Calendar that excludes all of the holidays.
We are going to implement the Calendar interface:
Here is the code of Calendar interface:
Above method returns a Boolean type values either true or false. Which takes long type value (timeStamp) in milliseconds and included by the Calendar interface.
This method takes long type value (timeStamp) in millisecond and determine the next time which is included by the Calendar after the given time.
The Quartz consists of the org.quartz.impl.HolidayCalendar class. The Calendar object integrated with the scheduler through the addCalendar() method. If you want to use the HolidayCalendar then first of all you must be initialized it, after that you will use the addExcludedDate(Date date) method in the program. This method is used to exclude the days from the scheduling.
Here we are going to implement a simple Calendar object to add and exclude with it:
HolidayCalendar hcal = new HolidayCalendar();
sched.addCalendar("myHoliday", hcal, false);
The triggers contains another important property that is "misfire instruction". Sometimes, a persistent trigger misses to its firing time because the scheduler being shutdown, in this case the misfire is occurred. More descriptions about the misfire instruction will provide below with the Simple and Cron Triggers. The misfire instruction can be used with trigger object by using the setMisfireInstruction() method.
Rs. 20,000 US$ 300
Today: Rs. 10,000 US$150
Course Duration: 30 hrs
Posted on: April 13, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles