In many cases, it is necessary to use timed scheduling, such as running a crawler at regular intervals to crawl new data, with quartz,spring task and timer
Spring Task can compare it to a lightweight quartz, and it is simple to use, except that there is no need for additional packages outside of spring-related packages
Recommended use of annotation-style implementations
Import Org.springframework.scheduling.annotation.scheduled;import org.springframework.stereotype.component;@ Componentpublic class Webtask { //every Five seconds @Scheduled (cron = "0/5 * * * * *?") public void Taskjob () { System.out.println ("Test");} }
In the relevant configuration, add this sentence configuration, no additional parameters
<task:annotation-driven/>
The specific analysis of Cron is as follows
Field Allow value allowed special characters sec 0-59 ,-*/min 0-59 ,-*/hour 0-23 ,-*/Date 1-31 ,-*?/L W C Month Part 1-12 or Jan-dec ,-*/week 1-7 or Sun-sat ,-*?/L C #年 (optional) Leave blank, 1970-2099 ,-*/
View Code
Quartz
Spring timed Dispatch