spring自带的定时任务框架

在做定时任务时,可以使用Spring自带的定时任务框架。
使用scheduled-tasks例子:
在spring配置文件中加入如下代码即可:

<task:scheduled-tasks scheduler="myScheduler">
    <task:scheduled ref="beanA" method="methodA" fixed-delay="5000" initial-delay="1000"/>
    <task:scheduled ref="beanB" method="methodB" fixed-rate="5000"/>
    <task:scheduled ref="beanC" method="methodC" cron="*/5 * * * * MON-FRI"/>
</task:scheduled-tasks>

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

需要引入task命名空间;
例如:xmlns:task=”http://www.springframework.org/schema/task”
xsi:schemaLocation=”http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd

spring定时框架详细见:http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#scheduling-annotation-support

猜你喜欢

转载自blog.csdn.net/zht666/article/details/53024213