Spring3 scheduled execution of tasks

Source: Internet
Author: User

A profile + a class to get it done:

1. configuration file, a

<task:scheduled-tasks> tags, ref represents the class that is executed, method is methods,
cron= "0 0/2 * * *?"
Executes every two minutes with a delay of 0 seconds
1 <?XML version= "1.0" encoding= "UTF-8"?>2 <Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"XMLNS:AOP= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"Xmlns:c= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/C"Xmlns:cache= "Http://www.springframework.org/schema/cache"Xmlns:context= "Http://www.springframework.org/schema/context"Xmlns:jdbc= "Http://www.springframework.org/schema/jdbc"Xmlns:jee= "Http://www.springframework.org/schema/jee"Xmlns:lang= "Http://www.springframework.org/schema/lang"Xmlns:mvc= "Http://www.springframework.org/schema/mvc"xmlns:p= "http://www.springframework.org/schema/p"Xmlns:task= "Http://www.springframework.org/schema/task"Xmlns:tx= "Http://www.springframework.org/schema/tx"Xmlns:util= "Http://www.springframework.org/schema/util"3 xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 4 HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/spring-aop.xsd5 Http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd 6 Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/ Spring-context.xsd7 HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/JDBC http://www.springframework.org/schema/jdbc/spring-jdbc.xsd8 Http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd9 Http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsdTen Http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd One Http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd A http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd - http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd "> -     <!--Cron Expression: * (seconds 0-59) * (minutes 0-59) * (Hours 0-23) * (Date 1-31) * (month 1-12 or JAN-DEC) * (week 1-7 or Sun-sat) -  the      <Task:scheduled-tasks> -         <task:scheduledref= "Taskcomponent"Method= "Logtest"Cron= "0 0/2 * * *?" /> -     </Task:scheduled-tasks>  - </Beans>

Java class

1 ImportOrg.apache.log4j.Logger;2 Importorg.springframework.beans.factory.annotation.Autowired;3 Importorg.springframework.stereotype.Component;4 ImportCom.test.TestService5 6 @Component7  Public classtaskcomponent8 {9 @AutowiredTen     PrivateTestservice Testservice; One     StaticLogger Logger = Logger.getlogger (taskcomponent.class); A      -      -      the      Public voidlogtest () -     { -         //define a Log object -Log log =Newlog (); +System.out.print ("Execute every two minutes, delay 0 seconds"); - testservice.save (log); +     } A      at}

Spring3 scheduled execution of tasks

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.