Simpletrigger should meet your scheduling needs if you need to has a job execute exactly once at a specific moment in time, or at a specific moment in time followed by repeats at a specific interval. For example, if you want the trigger-to-fire in exactly 11:23:54 AM on January,or if you want it to fire at the time, and then the fire five the more times, every ten seconds.
With this description, your may isn't find it surprising to find that the properties of a Simpletrigger include:a start- time, and End-time, a repeat Count, and a repeat interval. All of these properties is exactly what do you ' d expect them to is, with only a couple special notes related to the End-time Property.
The repeat count can be zero, a positive integer, or the constant value simpletrigger.repeat_indefinitely. The Repeat Interval property must is zero, or a positive long value, and represents a number of milliseconds. Note that a repeat interval of zero would cause ' repeat count ' firings of the trigger to happen concurrently (or as close t o concurrently as the Scheduler can manage).
If you're not already familiar with Quartz's Datebuilder class, you could find it helpful for computing your trigger Fire-ti Mes, depending on the startTime (or endTime) that's you ' re trying to create.
the EndTime Property (if it was specified) overrides the Repeat Count property. This can is useful if you wish to create a trigger such as one that fires every ten seconds until a given moment in time. Rather than have to compute the number of times it would repeat between the start-time and the end-time, you can simply Specify the end-time and then use a repeat count of repeat_indefinitely (you could even specify a repeat count of some hug E number that's sure to being more than the number of times the trigger would actually fire before the End-time arrives).
Examples of defining Triggers with Different schedules
The following is various examples of defining triggers with simple schedules. Review them all, as they each show at least one new/different point.
Also, spend some time looking at all of the available methods in the language defined by Triggerbuilder and Simpleschedule Builder So, can be familiar with options available to you and not having been demonstrated in the examples show n here.
Build a trigger for a specific moment in time, with no repeats
Simpletrigger trigger = (Simpletrigger) Jobbuilder.newtrigger () . Withidentity ("Trigger1", "group1" ) // some Date // . Build ();
Build a trigger for a specific moment in time, then repeating every ten seconds ten times:
Trigger = Jobbuilder.newtrigger () . Withidentity ("Trigger3", "group1") . StartAt ( mytimetostartfiring) // If a start time is no given (ifthis line . Withschedule (Simpleschedulebuilder.simpleschedule () . Withintervalinseconds() . Withrepeatcount (// Note that repeats would give atotal of/ / c18> identify job with handle to its jobdetail itself . Build ();
Build a trigger that'll fire once, five minutes on the future
Trigger = (Simpletrigger) Jobbuilder.newtrigger () . Withidentity ("Trigger5", "group1") . StartAt (datebuilder.futuredate (/ /// . Build ();
Build a trigger that'll fire now, then repeat every five minutes, until the hour 22:00
Trigger = Jobbuilder.newtrigger () . Withidentity ("Trigger7", "group1") . Withschedule ( Simpleschedulebuilder.simpleschedule (). withintervalinminutes (5). repeatforever ()) . endAt (Dateof (0, 0)) . Build ();
Build a trigger that would fire on the top of the next hour, then repeat every 2 hours, forever
Trigger =Jobbuilder.newtrigger (). Withidentity ("Trigger8")//because group is not specified, "Trigger8" would be in the default group. StartAt (Datebuilder.evenhourdate (NULL))//get the next even-hour (minutes and seconds zero ("00:00")). Withschedule (Simpleschedulebuilder.simpleschedule (). Withintervalinhours (2). RepeatForever ())//Note that the This example, ' Forjob (..) ' are not called//-which is valid if the trigger are passed to the scheduler along with the job. Build (); Scheduler.schedulejob (trigger, job);
Simpletrigger Misfire Instructions
Simpletrigger has several instructions so can be used to inform Quartz what it should does when a misfire occurs. (For information on misfires, see the About Triggers topic.) These instructions is defined as constants on Simpletrigger itself (including Javadoc, describes their behavior). These constants include:
Misfire_instruction_ignore_misfire_policy 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_with_existing_count
All triggers has the misfire_instruction_smart_policy instruction available for use, and this instruction is the default For all trigger types.
If the ' smart policy ' instruction is used, Simpletrigger dynamically chooses between its various misfile instructions, BAS Ed on the configuration and state of the given Simpletrigger instance. The Javadoc for the Simpletrigger.updateaftermisfire () method explains the details of this dynamic behavior.
When building simpletriggers, you specify the misfire instruction as part of the simple schedule (via Simpleschedulerbuild ER):
Trigger = Jobbuilder.newtrigger () . Withidentity ("Trigger7", "group1") . Withschedule ( Simpleschedule (). withintervalinminutes (5). repeatforever () . Withmisfirehandlinginstructionnextwithexistingcount ()) . Build ();
Quartz Scheduler (2.2.1)-Usage of Simpletrigger