spring定时任务详解

(一)在spring.xml里加入task的命名空间

  

xmlns:task="http://www.springframework.org/schema/task" 
http://www.springframework.org/schema/task 
http://www.springframework.org/schema/task/spring-task.xsd

 (二)启用注解驱动的定时任务

<task:annotation-driven executor="executor" scheduler="scheduler"/>

(三)配置定时任务的线程池

推荐配置线程池,若不配置多任务下会有问题。后面会详细说明单线程的问题。

  <task:scheduler id="scheduler" pool-size="10"/>

该处的id和(二)中的scheduler="scheduler"对应

(四)写我们的定时任务

猜你喜欢

转载自www.cnblogs.com/songsong003/p/10682615.html
今日推荐