Spring Timer Annotation Configuration

Source: Internet
Author: User

Spring-task.xml

<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"Xmlns:context= "Http://www.springframework.org/schema/context"Xmlns:mvc= "Http://www.springframework.org/schema/mvc"Xmlns:tx= "Http://www.springframework.org/schema/tx"Xmlns:task= "Http://www.springframework.org/schema/task"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans-3.1.xsd Http://www.springframework.org/schema/context Http://www.springframework.org/schema/con Text/spring-context-3.1.xsd Http://www.springframework.org/schema/tx HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/T X/spring-tx-3.1.xsd Http://www.springframework.org/schema/task http://www.springframework.org/schema/task/s Pring-task-3.1.xsd ">    <!--Default scanned package path -      <Context:component-scanBase-package="*" />      <!--SPRINGMVC Timer Switch -    <Task:annotation-driven/></Beans>

Web. XML (add the following code to Web. xml)

< Context-param >    < Param-name >contextconfiglocation</param-name>    <  Param-value>/web-inf/config/spring-task.xml</param-value>  </context-param>

Midtask.java

 PackageCom.henu.task;Importorg.springframework.scheduling.annotation.Scheduled;Importorg.springframework.stereotype.Component; @Component Public classMidtask {/*** timed calculation. Executes every five seconds*/@Scheduled (Cron= "0/5 * * * *?")        Public voidShow () {System.out.println ("Task1"); }    /*** timed calculation. Executes every 10 seconds*/@Scheduled (Cron= "0/10 * * * *?" )        Public voidZol () {System.out.println ("Task2"); }}

Spring Timer Annotation Configuration

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.