Quartz Timer Tool

Source: Internet
Author: User

Useful when working at a time. Just put some of the previous records also posted out to do a summary of the good.

1.quartz Core Interface Scheduler Scheduler,Job,jobdetail,Trigger,jobdatamap
2.Scheduler1. The implementation of this Scheduler is actually a proxy, on which the method invocation is passed to the Quartzscheduler instance 2.SchedulerFactory Instantiation 3.org.quartz.impl.directoschedulerfactory org.quartz.impl.StdSchedulerFactory stdschedulerfactory will load the quartz.properties file under the Classpath 4. Once scheduler is closed (shutdown), it cannot be restarted unless it is re-instantiated


3.job1.public interface Job {void execute (Jobexecutioncontext context) throws jobexecutionexception;} 2.StatefulJob re-stores jobdatamap after each execution of a task
4.JobDetail1.JobDetail objects are created by the Quartz client when the job is added to the scheduler. It contains the various settings properties of the job and a Jobdatamap object, which is used to store state information for a given job class instance.
2. Each time scheduler performs this task, it creates a new instance of the class and then calls the instance's execute (..) Method.
3.JobDataMap Jobdetail.getjobdatamap (). Put ("Jobsays", "Hello world!"); Jobexecutioncontext.getjobdetail (). Getjobdatamap (); Trigger.getjobdatamap (); Jobexecutioncontext.getmergedjobdatamap ();
5.Triggerthe 1.Trigger object is used to trigger the execution of jobs.
2. The commonly used trigger classes are Simpletrigger and Crontrigger.
3.SimpleTrigger The Simpletrigger is used to trigger a task that only executes once or is triggered at a given time and repeats n times for a certain amount of time per execution.
4.CronTriggers trigger tasks on a schedule like a calendar
5.TriggerUtils provides a number of convenient ways to simplify construction and configuration trigger Public static Trigger makesecondlytrigger (int intervalinseconds); Public static Trigger makedailytrigger (int hour, int minute); Public static Trigger makeweeklytrigger (int dayOfWeek, int hour, int minute); Public static Trigger makemonthlytrigger (int dayofmonth, int hour, int minute); Public static Date getnextgivenminutedate (date date, int minutebase); Public static Date getevenminutedate (date date);
6.Listeners1.TriggerListeners and Joblisteners a listener is an object that can perform an action when the scheduler event occurs. Triggerlisteners receiving events related to triggers The Joblisteners receives the job-related events.
2. Registration The listener then registers to scheduler at the time of execution The listener can be registered as "global" or "non-global"
Global: Scheduler.addglobaljoblistener (Joblistener);
Non-Global Scheduler.addjoblistener (Joblistener); Jobdetail.addjoblistener (Joblistener.getname ());
3.SchedulerListeners receive only scheduler self-event notifications unrelated to a specific trigger or job
method of 4.jobListener: jobtobeexecuted () method
Scheduler calls this method when Jobdetail will be executed.

· jobexecutionvetoed () method

Scheduler calls this method when Jobdetail is about to be executed, but is Triggerlistener rejected.

· jobwasexecuted () method

Scheduler calls this method after the jobdetail is executed.

5.Triggerlistener · GetName () method
and the previousJoblistenerThe sameTriggerlistnerinterface ofGetName ()Returns a string that describes the name of the listener. For a non-globalTriggerlistenerInAddtriggerlistener ()The name given in the method must be the same as the listener'sGetName ()The method return value matches.

· triggerfired () method

When the Trigger associated with the listener is triggered, theExecute ()Scheduler calls this method when the method is going to be executed. In the globalTriggerlistenerCase, this method is called for all Trigger.

· vetojobexecution () method

This method is called by Scheduler when the Job is about to be executed when the Trigger is triggered.Triggerlistenergives a choice to veto the execution of the Job. If this method returns True, the Job will not be executed for this Trigger trigger.

· triggermisfired () method

Scheduler calls this method when the Trigger misses the trigger. As the JavaDoc of this approach points out, you should focus on the logic of the long duration in this approach: long logic causes a domino effect when there are many Trigger that miss the trigger. You should keep this method as small as possible.

· Triggercomplete () method

Scheduler calls this method when the Trigger is triggered and the Job execution is completed. This is not to say that the Trigger will no longer be triggered, but only when the current Trigger trigger (and immediately after the Job execution) ends. This Trigger may have to be triggered more than once in the future.

7.SchedulerPlugin plug-inThe 1.Quartz provides an interface (Org.quartz.spi.SchedulerPlugin) to insert additional functionality.
2.public interface Schedulerplugin { Public void Initialize (String name, Scheduler Scheduler) throws schedulerexception; Public void Start (); Public void Shutdown (); }
8.Quartz Cron1. Table 5.1. Quartz Cron expressions support to seven domains
Name Whether you must Allowed values Special characters
Seconds Is 0-59 , - * /
Score of Is 0-59 , - * /
When Is 0-23 , - * /
Day Is 1-31 , - * ? /L W C
Month Is 1-12 or Jan-dec , - * /
Week Is 1-7 or Sun-sat , - * ? /L C #
Years Whether Empty or 1970-2099 , - * /

2.* asterisk
Use an asterisk (*) to indicate that you want to include all valid values on this domain. For example, using an asterisk on a month field means that the trigger is triggered every month.

3.? Question Mark
? Can only be used on day and week fields , but cannot be used concurrently on both domains. You can think of that ? the character is "I don't care what the value is on that field." "This differs from the asterisk, which indicates each value on the field." Is that you do not specify a value for the field.

4., comma
A comma (,) is used to specify a list of values on a domain. For example, using the value 0,15,30,45 on the second field means that a trigger is triggered every 15 seconds.

5./ slash
The slash (/) is used for the increment of the timesheet. We've just used a comma to indicate a 15-minute increment, but we can also write this 0/15.

6.-Middle Dash
A medium dash (-) is used to specify a range. For example, 3-8 on the hour field means "3,4,5,6,7 and 8 points." "The value of the domain does not allow a rollback, so a value like 50-10 is not allowed.

7.L describes the last value allowed on a domain. It is supported only by the day and week fields. When used on a day field, represents the last day of the month specified on the month field. For example, when JAN is specified on the current month field, L on the Japanese field will cause trigger to be triggered on January 31.
8.W Letter
The W character represents weekdays (Mon-fri) and can only be used in the day domain. It is used to designate the most recent weekday from the specified day
9.# number of Wells
The # character can only be used in the field of the week . It is used to specify which day of the week of the month. For example, if you specify the value of the week field as 6#3, it means the third Friday of the month (6= Friday,#3 means the third week in the month).







Quartz Timer Tool

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.