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
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.
Here is the also mis-fire instruction that have used for all trigger types:
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.
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