The Spring-task of spring task scheduling

Source: Internet
Author: User

Some time ago, the timer function should be used in the work

1. First configuration in Web. xml

<!--Configuring the spring core servlet--
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

2. Turn on the timing switch

Open in Spring-servlet.xml

<beans xmlns= "Http://www.springframework.org/schema/beans" xmlns:xsi= "http://www.w3.org/2001/ Xmlschema-instance "xmlns:p=" http://www.springframework.org/schema/p "xmlns:task=" http://www.springframework.org /schema/task "xmlns:context=" Http://www.springframework.org/schema/context "xmlns:aop="/HTTP/ Www.springframework.org/schema/aop "xsi:schemalocation=" Http://www.springframework.org/schema/beans/http Www.springframework.org/schema/beans/spring-beans-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/jee/HTTP Www.springframework.org/schema/jee/spring-jee-3.0.xsd Http://www.springframework.org/schema/context/HTTP Www.springframework.org/schema/context/spring-context-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/task/HTTP Www.springframework.org/schEma/task/spring-task-3.0.xsd "><task:annotation-driven/> <!--timer switch--><!--automatically scanned package name-->< Context:component-scan base-package= "Com.zxl78585.springtask.task"/><bean id= "MyTask" class= " Com.zxl78585.springtask.task.MyTask "></bean><task:scheduled-tasks><!--This is done every five seconds--   <task:scheduled ref= "MyTask" method= "show" cron= "*/10 * * * * *?"/></task:scheduled-tasks></beans>

3. Write your own timer

public class MyTask {public void Show () {System.out.println (New Date (). GetTime ());}}

The Spring-task of spring task scheduling

Related Article

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.