· Spring Timing Controller configuration file implementation method
I. Preparation of a normal business class
Public classSyncdatatasktimer {Private Final StaticLogger log = Logger.getlogger (Syncdatatasktimer.class); /*** Synchronized Organization*/ Public voidsyncorg () {Log.info ("Sync Organization:" +System.currenttimemillis ()); } /*** Synchronize Users*/ Public voidSyncuser () {Log.info ("Synchronizing Users:" +System.currenttimemillis ()); } }
Two. Applicationcontext-task.xml configuration file
<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:context= "Http://www.springframework.org/schema/context"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"XMLNS:AOP= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"Xmlns:tx= "Http://www.springframework.org/schema/tx"Xmlns:jee= "Http://www.springframework.org/schema/jee"Xmlns:task= "Http://www.springframework.org/schema/task"xsi:schemalocation= "Http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd/http Www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http ://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd/http WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/spring-aop-3.0.xsd/HTTP WWW.SPRINGFRAMEWORK.ORG/SCHEMA/TX http://www.springframework.org/schema/tx/spring-tx-3.0.xsd/HTTP Www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd "> <!--Spring timed task configuration Items - <BeanID= "Scheduledtask"class= "Org.springframework.scheduling.timer.ScheduledTimerTask"/> <!--synchronizing IPM Data-timed task configuration - <BeanID= "Syncdatatasktimer"class= "Cn.chinaunicom.pmis.interfaces.ipm.server.task.SyncDataTaskTimer"/> <!--task time Item configuration - <Task:scheduled-tasks> <task:scheduledref= "Syncdatatasktimer"Method= "syncorg"Cron= "0 * * *?"/> <task:scheduledref= "Syncdatatasktimer"Method= "Syncuser"Cron= "0 * * *?"/> </Task:scheduled-tasks>
Three. Applicationcontext.xml references
<!---<resource= "Applicationcontext-task.xml" />
Note: The spring configuration file is split here.
----------------------------------------Split Line-----------------------------------------
· Analysis of difficulties
I. CRON syntax
<task:scheduled ref= "Syncdatatasktimer" method= "syncorg" cron= "0 30 23 * *?" />
cron= "0 30 23 * *?" It means to do it 23:30 every day.
Cron syntax usage and character interpretation
Cron syntax for use
* |
* |
* |
* |
* |
* |
[*] |
Seconds |
Score of |
When |
Day |
Month |
Week |
Years |
Spring-task-timer Timer