Spring scheduled task (2)

Source: Internet
Author: User

Project Description: synchronize data between platforms: 1: Spring applicationContext. the xml configuration file is as follows (only the timer configuration is described): <bean id = "jobtask" class = "org. springframework. scheduling. quartz. methodInvokingJobDetailFactoryBean "> <! -- Name of the called class action --> <property name = "targetObject"> <ref bean = "synchroDataAction"/> </property> <! -- Call methods in the class: execute method in action --> <property name = "targetMethod"> <value> execute </value> </property> </bean> <! -- Trigger --> <bean id = "cronTrigger" class = "org. springframework. scheduling. quartz. CronTriggerBean"> <! -- Point to our task --> <property name = "jobDetail" ref = "jobtask"/> <! -- Run at every Monday morning --> <! -- <Property name = "cronExpression" value = "0 0 1? * MON "/> --> <! -- Run the test once in five seconds --> <! -- <Property name = "cronExpression" value = "*/50 ****? "/> --> <Property name =" cronExpression "value =" 0 0 */1 **? "/> </Bean> <! -- Scheduler --> <bean class = "org. springframework. scheduling. quartz. SchedulerFactoryBean" autowire = "no"> <property name = "triggers"> <list> <! -- Trigger list --> <ref bean = "cronTrigger"/> </list> </property> </bean> 2: The action layer calls the Service layer method synchroDataService. synchrodata (); 3: service layer: InputStream inputStream = null; OutputStream fos = null; try {SimpleDateFormat sdformat = new SimpleDateFormat ("yyyy-MM-dd HH: mm: ss "); // inputStream = new FileInputStream (this. getClass (). getClassLoader (). getResource ("webData. properties "). getPath (); inputStream = This. getClass (). getClassLoader (). getResourceAsStream ("webData. properties "); Properties properties = new Properties (); properties. load (inputStream); String updateID = new String (properties. getProperty ("updateID "). getBytes ("ISO8859_1"), "UTF-8"); String registerID = new String (properties. getProperty ("registerID "). getBytes ("ISO8859_1"), "UTF-8"); if (inputStream! = Null) {inputStream. close ();} String code_update [] = {"SYS302001", "SYS302003"}; String code_register [] = {"SYS302005", "SYS302006 "}; fos = new FileOutputStream (this. getClass (). getClassLoader (). getResource ("webData. properties "). getPath (); if (StringUtils. isNotEmpty (updateID) {List <PlatformUser> listU = getListData (code_update, updateID, sdformat); dataInsert (listU, sdformat); properties. setP Roperty ("updateID", MaxID);} if (StringUtils. isNotEmpty (registerID) {List <PlatformUser> listR = getListData (code_register, registerID, sdformat); dataInsert (listR, sdformat); properties. setProperty ("registerID", MaxID);} properties. store (fos, null);} finally {if (fos! = Null) {fos. flush (); fos. close ();}}

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.