write Java business code that needs to be added on top of the class declaration@Component Annotations and add @scheduled (cron = "0/5 * * * * *") on the method declaration that requires timed task execution Annotations and related parameters
Package Com.gf.test.core.schedule;import Org.joda.time.datetime;import Org.slf4j.logger;import Org.slf4j.loggerfactory;import Org.springframework.scheduling.annotation.scheduled;import org.springframework.stereotype.Component; @Componentpublic class Scheduletest {private static final Logger Logger = Log Gerfactory.getlogger (Scheduletest.class); @Scheduled (cron = "0/5 * * * * *?") public void Test () {Logger.info (New DateTime (). toString ()); }}
Timed Task Instances
"0 0 12 * * ?" Daily 12 o'clock Noon trigger "0 15 10 ? * *" 10:15 "0 15 10 * * ?" 10:15 trigger "0 15 10 * * ? *" every day 10:15 "0 15 10 * * ? 2005 "2005 Years a day 10:15 trigger" 0 * 14 * * ? " Daily from 2 o'clock in the afternoon to 2:59 every minute trigger "0 0/5 14 * * ?" Every 5 minutes from 2 o'clock in the afternoon to 2:55 each day triggers "0 0/5 14,18 * * ?" Every 5 minutes from 2 o'clock in the afternoon to 2:55 and 6 to 6:55 each time the "0 0-5 14 * * ?" is triggered. Daily from 14:00 to 14:05 per minute trigger "0 10,44 14 ? 3 wed" every Wednesday 14:10 and 14:44 triggers "0 15 10 ?" in March. * mon-fri "Every Monday, Tuesday, Wednesday, Thursday, Friday 10:15 triggers" 0 15 10 15 * ? " 10:15 of the monthly number 15th triggers "0 15 10 L * ?" 10:15 of the last day of the month triggers "0 15 10 ? * 6l" The last Friday of the month for the 10:15 trigger "0 15 10 ? * 6l 2002-2005 "2002 to 2005 of the last Friday of the month 10:15 trigger" 0 15 10 ? * 6#3 "the third Friday of 10:15 triggers" 0 0 */1 * * ? " Execute "0 0/5 * * * ?" once per hour. Executed every five minutes
Reference address:http://blog.csdn.net/tuzongxun/article/details/51576301
Springcloud timed Task Configuration