1.spring+task file Configuration
1<?xml version= "1.0" encoding= "UTF-8"?>2<beans xmlns= "Http://www.springframework.org/schema/beans"3Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"4xmlns:task= "Http://www.springframework.org/schema/task"5xmlns:context= "Http://www.springframework.org/schema/context"6xsi:schemalocation= "Http://www.springframework.org/schema/task http://www.springframework.org/schema/task/ Spring-task-4.2.xsd7http//Www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd8http//Www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-4.2.xsd">9 Ten One<task:annotation-driven/> A<context:component-scan base- Package= "Com.task"/> -</beans>
View Code
2. Business Class
1 PackageCom.task;2 3 Importorg.springframework.scheduling.annotation.Scheduled;4 Importorg.springframework.stereotype.Component;5 6 @Component7 Public classtestscheduled {8 9@Scheduled (cron= "0/5 * * * *?) ")//executes once every 5 secondsTen Public voidTest () { One for(Longi=0;i<1000000000000000000l;i++){ ASystem.out.print ((Char) (i); - if(i%15==0){ - System.out.println (); the } - } - } -}
View Code
Start the program and start running.
Spring+task Configuration