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