Home » Java » Timed tasks for spring

Timed tasks for spring




The first type: (@Scheduled annotation)



1, add a space named

in the core configuration file in spring
xmlns:task= "http://www.springframework.org/schema/task""
Http://www.springframework.org/schema/task
Http://www.springframework.org/schema/task/spring-task.xsd






2, annotations for timed tasks are enabled.


// multi task allocation of the thread pool, otherwise the project will fail ID can name


3, add the annotation

on the method that needs to perform the timed task
@Scheduled (cron= "0/3 * * * *?") / / every 3 seconds to execute a specific parameter configuration of their search
Public void (getA) {
System.out.println ("A >>>>>>>>>>>>>>>>>>>>>>>>>>>>>.. Mission");
}
@Scheduled (cron= "0/4 * * * *?")
Public void (getB) {
System.out.println ("B >>>>>>>>>>>>>>>>>>>>>>>>>>>>>.. Mission");
}






Latest