首页 > 编程语言 > 详细

spring定时器

时间:2016-07-15 13:50:48      阅读:159      评论:0      收藏:0      [点我收藏+]

Spring定时任务

    用过其他几个定时器,最近发现spring定时器超级好用

    1、首先在xml文件头中添加

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

         xsi:schemaLocation="http://www.springframework.org/schema/task/spring-task-3.2.xsd"

    2、在xml文件中添加

        <task:executor id="executor" pool-size="5" />    
        <task:scheduler id="scheduler" pool-size="10" />    
        <task:annotation-driven executor="executor" scheduler="scheduler" />     

    3、在执行类中通过注释@Scheduled(cron="0 0/5 * * * ?")就会被调度

  

    在定时多任务的时可以通过配置文件定义

    @PropertySource("classpath:activity.properties")

    @Scheduled(cron ="${taks.job}")

    并在activity.properties中添加 taks.job ="0 0/5 * * * ?"



需要注意 <context:component-scan base-package="*" /> 必须在spring扫描的包内,否则无法进行调度。

spring定时器

原文:http://5474584.blog.51cto.com/5464584/1826613

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!