Spring's scheduled use annotation way to dispatch, feel very convenient, at least the configuration of things a lot less, so stay to forget, first to configure our Spring.xmlxmlns add the following content, xmlns:task = "Http://www.springframework.org/schema/task" then xsi:schemalocation add the following content, http://www.springframework.org/ schema/taskhttp://www.springframework.org/schema/task/spring-task-3.1.xsd finally is our task Task Scan annotation <task: annotation-driven/> My configuration Scan location is: <context:annotation-config/> <bean class= " Org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor "/><context: Component-scan base-package= "com.test"/> scan the contents of a package such as com.test, the following need interface and implementation (my several Java files are under the Com.test package,) public interface Imytestservice { public void MyTest (); } @Component //import org.springframework.stereotype.Component; public class Mytestserviceimpl implements imytestservice { @Scheduled (cron= "0/5 * * * *? ") //execute once every 5 seconds &NBSP @Override public void MyTest () { System.out.prin TLN ("Enter Test"); } } after execution the console will print into the test the points to note: 1, Spring's @scheduled annotations Need to write on the implementation, 2, the Timer task method can not have a return value (if there is a return value, spring initialization will tell you that there is an error, you need to set a Proxytargetclass value of true, the specific to Baidu Google bar) 3, Implement annotations for components on a class @component the rest of the corn expression is a cron expression with at least 6 (or possibly 7) time elements separated by a space. In order seconds (0~59) minutes (0~59) hours (0~23) days (months) (0~31, but you need to consider the number of days in your month) month (0~11) Days (weeks) (1~7 1=sun or Sun,mon,tue,wed,thu,fri,sat) year (1970-2099) where each element can be a value (such as 6), a continuous interval (9-12), A time interval (8-18/4) (/= every 4 hours), a list (1,3,5), wildcard characters. Because the "date in the month" and "date in the week" are mutually exclusive, one of the two elements must be set. 0 0 10,14,16 * *? Daily 10 o'clock in the morning, 2 o'clock in the afternoon, 4 o ' 0 0/30 9-17 * *? &NBSP;0 0 12 for every half hour during the nine-night five working hours? * WED for each Wednesday noon 12 o'clock "0 0 12 * *?" Daily 12 O'Clock "0 15 10? * * "10:15 trigger " 0 15 10 * * "10:15 per day " 0 15 10 * *? * "Daily 10:15 Trigger &Nbsp; "0 15 10 * *? 2005 "2005-year 10:15 trigger 0 * 14 * *?" Every 1 minutes during 2 o'clock in the afternoon to 2:59 "0 0/5 14 * *?" triggers every 5 minutes during daily 2 o'clock in the afternoon to 2:55 "0 0/5 14,18 * * *" triggers every 5 minutes from 2 o'clock in the afternoon to 2:55 and 6 o'clock in the afternoon to 6:55 0 0-5 14 * *? "Every 1 minutes during daily 2 o'clock in the afternoon to 2:05 " 0 10,44 14? 3 WED "Every March Wednesday 2:10 and 2:44 trigger " 0 15 10? * Mon-fri "Monday to Friday 10:15 trigger " 0 15 10 15 *? "15th 10:15 trigger " 0 Ten L *? "10:15 trigger on the last day of the month " 0 15 10? * 6L "last Friday 10:15 trigger " 0 15 10? * 6L 2002-2005 "2002 to 2005 the last of the monthly Friday 10:15 trigger " 0 15 10? * 6#3 "The third Friday 10:15 of the month triggers some sub-expressions can contain ranges or lists For example: sub-expressions (days (weeks)) can be" Mon-fri "," Mon,wed,fri "," Mon-wed,sat " " * " The character represents all possible values Therefore, "*" in the sub-expression (month) represents the meaning of each month, "*" in the subexpression (Day (week)) represents the day of the week "/" character used to specify the increment of the numeric value For example: "0/15" in sub-expressions (minutes) means starting from the No. 0 minute, every 15 minutes in sub-expressions (minutes) "3/20" means starting from the 3rd minute, every 20 minutes (it and " 3,23,43 ") mean the same as "? "Character is used only for days (months) and days (weeks) two sub-expressions, indicating that no value is specified when one of the 2 sub-expressions is specified value, in order to avoid conflicts, another child needs to beThe value of an expression is set to "? The L character is used only for days (months) and days (weeks) of two sub-expressions, which is the abbreviation for the word "last" but it has different meanings in two sub-expressions. in the day (month) subexpression, "L" represents the last day of one months in the day (week) Self-expression, "L" represents the last day of one weeks, that is, sat if there is specific content before "L", it has other meanings for example: " 6L "represents the 6th day of the month," Fril "represents the month's most Friday NOTE: When using the" L "parameter, do not specify a list or range because this causes problems
Spring Scheduled Tasks