Quartz can be used to perform task scheduling functions, such as calling execution tasks at intervals of time. It's quite handy to use. Just configure the class you want to call to the spring configuration file.
Configure the quartz in the spring configuration file.
1 <!--the work class to invoke -2 <BeanID= "Quartzjob"class= "Com.aisino.projects.supply.task.Quartzjob"></Bean>3 <!--timed task activity effective and invalid -4 <BeanID= "Jobtask"class= "Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">5 <!--the class that is called -6 < Propertyname= "TargetObject">7 <refBean= "Quartzjob"/>8 </ Property>9 <!--calling methods in a class -Ten < Propertyname= "Targetmethod"> One <value>Job</value> A </ Property> - </Bean> - <!--Define trigger Time - the <BeanID= "Dotime"class= "Org.springframework.scheduling.quartz.CronTriggerFactoryBean"> - < Propertyname= "Jobdetail"> - <refBean= "Jobtask"/> - </ Property> + <!--cron-expression - - < Propertyname= "Cronexpression"> + <value>0 1 0 * *?</value> A </ Property> at </Bean> - <!--General Management Class if you lazy-init= ' false ' then the container starts executing the scheduler - - <BeanID= "Startquertz"Lazy-init= "false"Autowire= "No"class= "Org.springframework.scheduling.quartz.SchedulerFactoryBean"> - < Propertyname= "Triggers"> - <List> - <refBean= "Dotime"/> in </List> - </ Property> to </Bean>
For example, in line 2nd, configure the class to invoke, line 11th configures the method to invoke, and line 21st configures the time to invoke.
Time. The corn expression used here. The parameters are as follows:
Special characters allowed for field allowed values
Seconds 0-59,-*/
Sub 0-59,-*/
Hours 0-23,-*/
Date 1-31,-*? /L W C
Month 1-12 or JAN-DEC,-*/
Week 1-7 or Sun-sat,-*? /L C #
Year (optional) leave blank, 1970-2099,-*/
“?” Character: Represents an indeterminate value
"," character: Specify a number of values
"-" character: Specifies the range of a value
"/" character: Specifies the increment of a value. N/m means starting with N, increasing m each time
"L" character: Used on the last day of the one month, used in the week to represent the last one weeks of the month X
"W" character: Specifies the most recent weekday from the given date (Monday to Friday)
The "#" character: The number of weeks that the month is X. 6#3 said the 3rd Friday of the Month
So: In the above example, the Quartzjob class job method is executed once every 00:01. If multiple task schedules are required, only the 2nd and 3 of the 4 beans above will be repeated, then the trigger time is configured in the list of the 4th Bean. Of course, the premise is that your dispatch must exist in a class ~
Configuration and corn expression of quartz in spring