Home Quartz More About Simple Trigger
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

More About Simple Trigger

Advertisement
Simple trigger can be used to one shot execution or fire a job and in other words, we can say that just a single execution of job to the specified time.

More About Simple Trigger

     

Simple trigger can be used to one shot execution or fire a job and in other words, we can say that just a single execution of job to the specified time. Sometimes, we wish to execute or fire a job at the specified time that has till 'N' repetition times with delay between 'T' executions of jobs that means if you need to have a job execute exactly once at a specific time, or at a specific moment in time that is followed by repeats at a specified time interval.

The SimpleTrigger properties contains: a start-time and end-time, a repeat count and a repeat interval. The repeat count properties can be zero, a positive integer or the constant value SimpleTrigger.REPEAT_INDEFINITELY. The repeat interval property must be zero or a positive long value that represents a number of milliseconds. The end-time property over-rides the repeat count property that can be used for creating a trigger which fires every some specified time (20 seconds). It has to compute the number of times that would be repeated between the start-time and end-time, if we want to specify the end-time then we can use a repeat count of REPEAT_INDEFINITELY.

We are going to implement a SimpleTrigger constructor to following types:

public SimpleTrigger(String name, String group, Date startTime, Date endTime, int repeatCount, long repeatInterval);
 
This is the constructor of java.org.quartz.SimpleTrigger class. Which fires or executes at the specified time and repeat at the specified number of times. It takes following arguments like this:

    name: This is the name of Simple Trigger.
  group:
This is the name of scheduler group.
  startTime: 
This is the time for firing or executing the Trigger.
  endTime:
This is the time for the Trigger to drop repeat firing or executing. 
  repeatCount:
This is the number of repeat firing or executing the Trigger by using the REPEAT_INDEFINITELY  for no any foundation of time.
  repeatInterval:
This is the time (milliseconds) for stopping or pausing the repeat firing.

There are following examples for implementing the SimpleTrigger:

1. Example SimpleTrigger : Create a simple trigger which fires exactly once, 20 seconds from now:

long startTime = System.currentTimeMillis() + (20L*1000L);

SimpleTrigger strigger  =  new SimpleTrigger("mySimpleTrigger", sched.DEFAULT_GROUP, new Date(startTime), null, 0, 0L);

2. Example SimpleTrigger : Create a simple trigger that fires quickly and repeats every 20 seconds:

SimpleTrigger strigger  =  new SimpleTrigger("mySimpleTrigger", sched.DEFAULT_GROUP, new Date(), null, SimpleTrigger.REPEAT_INDEFINITELY, 20L * 1000L);

3. Example SimpleTrigger: Create a Simple Trigger that fires quickly and repeats every 10 seconds until 50 seconds from now:

long endTime = System.currentTimeMillis() + (50L * 1000L);

SimpleTrigger strigger  =  new SimpleTrigger("mySimpleTrigger", sched.DEFAULT_GROUP, new Date(), new Date(endTime), SimpleTrigger.REPEAT_INDEFINITELY, 10L * 1000L);

4. Example SimpleTrigger: Create a Simple Trigger that fires on February 19 of the year 2007 at accurately 9:15 am, and repeats 10 times with 20 seconds delay between each firing.

java.util.Calendar cal = new java.util.GregorianCalendar(2007,cal.FEB, 19);
cal.set(cal.HOUR, 9);
cal.set(cal.MINUTE, 15);
cal.set(cal.SECOND, 0);
cal.set(cal.MILLISECOND, 0);

Data startTime = cal.getTime();

SimpleTrigger trigger = new SimpleTrigger("mySimpleTrigger", sched.DEFAULT_GROUP, startTime, 10, 20L*1000L);

Simple Trigger Misfire Instructions

When the misfire instruction occurs then what should to do the Quartz. There are following misfire instructions to use for informing the Quartz.

  MISFIRE_INSTRUCTION_FIRE_NOW

     MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_EXISTING_REPEAT_COUNT

   MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_REMAINING_REPEAT_COUNT

   MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_REMAINING_COUNT

   MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_EXISTING_COUNT

Here is the also mis-fire instruction that have used for all trigger types:

   Trigger.MISFIRE_INSTRUCTION_SMART_POLICY

When we will use the "smart policy" misfire instruction with the triggers then the SimpleTrigger determine between its various types of mis-fire instructions that depends upon the configuration and state of the specified SimpleTrigger instance. The JavaDOC has the SimpleTrigger.updateAfterMisfire() method that describes the brief description of this dynamic behavior.

Advertisement

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

Ask Questions?    Discuss: More About Simple Trigger  

Post your Comment


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