Spring-task-timer Timer

Source: Internet
Author: User

· 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.