Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Quartz More About Triggers

Related Tutorials


 
 

Share on Google+Share on Google+

More About Triggers

Advertisement
In this section we will try to provide the brief description of triggers.

More About Triggers

     

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.

Calendars

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:

package org.quartz;

  public interface Calendar {
  public boolean isTimeIncluded(long timeStamp);
  public long getNextIncludedTime(long timeStamp);
  }

isTimeIncluded(long timeStamp);
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.

getNextIncluedeTime(long timeStamp);
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();
cal.addExcludedDate(Date date);

sched.addCalendar("myHoliday", hcal, false);

Misfire Instructions
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.

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 13, 2007

Related Tutorials

Discuss: More About Triggers   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com