spring task任务计划

spring3.0以后支持自带的任务计划spring task,具体配置分为注解和xml两种方式,注解使用@Scheduled,同时需要在xml中配置<task:annotation-driven/>,具体如下:

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

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

这里重点说一下xml配置

<?xml version="1.0" encoding="UTF-8,2685561208,2499486051"?>

<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"

xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"

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

xsi:schemaLocation="http://www.springframework.org/schema/beans

           http://www.springframework.org/schema/beans/spring-beans.xsd

           http://www.springframework.org/schema/context

           http://www.springframework.org/schema/context/spring-context.xsd

           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd

           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd

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

        <task:scheduler id="scheduler" pool-size="2" /><!--一般小于等于task:scheduled数,但不能过小-->

       <task:scheduled-tasks scheduler="scheduler">

                 <task:scheduled ref="synDataFromPortalTask" method="synOrgData" cron="0 0 2 * * ?"/>

                 <task:scheduled ref="msgSendTask" method="sendMsg" cron="0 0/3 8-18 * * ?"/>

        </task:scheduled-tasks>

</beans>

猜你喜欢

转载自sfc235300.iteye.com/blog/2283359