xml configuration task using the timing spring

In development will often encounter do regular tasks needs, such as regular cleaning and log processing, data timing synchronization information and other needs.

1. Use in the spring configuration xml regular tasks, as follows

 <!-- ftpiptv信息同步接口定时任务配置-->
    <!-- 定时任务要工作的bean-->
    <bean id="ftpIptvInfo" class="com.zznode.task.TerminalTestTask"/>
    <!-- 定义生成工作对象的工厂,并为工厂设定目标对象targetObject属性、目标对象的工作方法targetMethod属性 -->
    <bean id="ftpIptvInfoFactoryBean"
          class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <property name="targetObject" ref="ftpIptvInfo" />   //这个是目标类
        <property name="targetMethod" value="iptvUpLoad" />  //需要执行的方法
    </bean>
    <!-- 任务调度计时器,进行定时设置。CronTriggerFactoryBean能进行非常精确的定时设置 -->
    <bean id="ftpIptvInfoTimer"
          class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
        <property name="jobDetail" ref="ftpIptvInfoFactoryBean" />
        <property name="cronExpression" value="0 0 0 * * ? " />
    </bean>
<!-- 调度任务触发器,启动定时任务-->
    <bean id="startQuartz" lazy-init="true" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="triggers">
            <list>
                <ref bean="ftpIptvInfoTimer"/>
            </list>
        </property>
    </bean>

2.cronExpression expression

Cron expression is a string of 5 or 6 separated by a space, is divided into six or seven domains, each domain representing a meaning, Cron following two syntax:
  (. 1) Hours Minutes Seconds The dayOfMonth Month Year DayofWeek
  (2) hours minutes seconds the fast-dayOfMonth month DayofWeek
a structural
  second minute hour day of the month date week month year: corn left to right (separated by spaces)
meaning second, each field

  Note: Each domain using digital, but may also be present as a special character, their meanings are:
  (1) : represents any value matches the domain. If used in the Minutes field , it means that every minute a trigger event.
  (2) can only be used ?: DayofMonth and DayofWeek two domains. It also matches any value of the field, but actually not. Because DayofMonth and DayofWeek affect each other. For example, you want to trigger scheduled on the 20th of each month, regardless of the 20 in the end of the week, you can only use the following wording:? 13,131,520 *, which can only be the last one? , Can not be used , if used representation regardless of the day of the week will be triggered, in fact not the case.
  (3) -: indicates a range. 5-20 Minutes domain using, for example, represents 20 minutes from 5 assigned to the trigger once per minute
  (4) /: indicating a start time of a start trigger, and a trigger every predetermined time. For example, in the domain 5/20 Minutes, it means five minutes once triggered, 25, 45, respectively, while the trigger once.
  (5) ,: listed represent the enumeration values. For example: the use of 5,20 in Minutes field, it means that the trigger once per minute at 5 and 20 minutes.
  (6) L: represents the last, and only appeared in DayofWeek DayofMonth domain. If you use 5L in DayofWeek domain, meaning that triggered last Thursday.
  (7) W: represents the effective working days (Monday to Friday), can only appear in DayofMonth domain, the system will trigger events in recent days from the effective date specified. For example: the use of 5W in DayofMonth, if the 5th is a Saturday, then in recent days: Friday that the 4th trigger. If the 5th is a Sunday, then on the 6th (Zhouyi) is triggered; if, in the Friday day, it triggers on Monday 5th in the 5th. Another point, W recently looking for does not cross the month.
  (8) LW: These two characters can be used in conjunction, represent the last working day in a month, and last Friday.
  (9) #: means for determining a month the first few days of the week, only appear in DayofMonth domain. For example, in 4 # 2, it represents the second Wednesday of the month.
Third, the common expression example
  ? (1) 0021 * * Denotes task execution timing of each month 2:01 Day
  (2) 0 15 10 * MON -FRI said Monday to Friday 10 hours a day?: 15 to perform the job
  ? (3) 0 15 10 6L 2002-2006 represents 2002-- 2006, the last Friday of each month at 10:15 am for the implementation of
  (4) 00 10,14,16 * * 10:00 every day? , 14:00, 4:00
  (5) * * 0 0/30 9-17? towards every half hour in the nine to five working hours
  (6) 0 0 12? * WED represent every Wednesday 12:00
  (7) 0 0 12 * *? 12:00 daily trigger
  (8) 01 510? * * 10:15 am daily trigger
  (9) 01510 * *? 10:15 am daily trigger
  (10) 01510 * *? * 10:15 every morning trigger
  (11) 01510 * *? 2005 10:15 am every day of the 2005 trigger
  (12) 0 14 * * *? triggered during every minute of every day at 2:00 pm to 2:59 pm
  (13) 0/5 0 14 * *? during 2:00 pm to 2:55 pm each day of the trigger every 5 minutes
  (14) 0/5 0 * 14, 18 *? During 2:00 to 2:55 every afternoon and trigger every 5 minutes 6:00 pm to 6:55 period
  (15) 00-514 * *? In every day triggered every minute 2:00 pm to 2:05 pm during the
  (16) 0 10,44 14? 3 WED March of each year Wednesday afternoon 2:10 and 2:44 trigger
  (17) 0 15 10? * MON- FRI Monday to Friday 10:15 am to trigger
  (18) 0151015 *? 15th of each month at 10:15 am on the trigger
  (19) 0 15 10 L * ? last day of each month at 10:15 am trigger
  ( 20) 0 15 10? * 6L last Friday of each month at 10:15 am on the trigger
  (21) 0 15 10? * 6L 2002-2005 2002 to 2005 years last Friday of each month at 10:15 am on the trigger
  (22 ) 01510? * the third Friday of each month at 10:15 am # 3 of 6 trigger

  Notes:
  (1) some sub-expressions can contain a range or list
  such as: sub-expressions (days (weeks)) can be "MON-FRI", "MON, WED, FRI", "MON-WED, SAT"
* * 1. "*" character represents all possible values
  therefore, " " indicates the meaning of each month in the sub-expression (month), the " " in the sub-expression (days (weeks)) represent each day of the week
  
2. "/" character is used to increment a specified value
  , for example: in the subexpression (minutes) in the "0/15" starts from 0 minutes, every 15 minutes
in the sub-expression (minutes) in the "3/20 "starts from the first three minutes, every 20 minutes (and it" 3,23,43 ") as meaning
  
3."? "character is used only two sub-day (month) and day (week) expression that do not specify a value **

  When one of the two sub-expressions which are assigned a value in the future, in order to avoid conflict, you need to set the value of another sub-expression "?"
  "L" character is used only day (month) and day (week) two subexpression, it is an abbreviation of the word "last" of
  it meaning in the two sub-expressions is different.
  Day (month) sub-expression, "L" represents the last day of the month
  in the day (week) from the expression, "L" represents the last day of the week, which is the SAT
  If there are specific in the "L" before content, it has the other meanings
  such as: "6L" the reciprocal of the sixth day of the month, "FRIL" represents the best Friday of the month
  Note: when using the "L" parameter, do not specify the list or range, because this can cause problems.

Finally: Online cron Expression Builder: http://cron.qqe2.com/
Corn expression Original Reference: https://www.cnblogs.com/javahr/p/8318728.html

Guess you like

Origin www.cnblogs.com/jasonboren/p/12081834.html