Spring定时器

[xhtml] view plain copy
  1. <!-- 配置定时器 -->  
  2.    <bean id="scheduleReportTask" class="org.springframework.scheduling.timer.ScheduledTimerTask">  
  3.         <property name="timerTask" ref="battleTimerTask"/>  
  4.         <property name="period" value="10000" /> <!-- 间隔,毫秒 -->  
  5.         <property name="delay" value="60000" /> <!-- 多久后启动Spring定时器,毫秒 -->  
  6.    </bean>  
  7.    <!-- Spring的TimerFactoryBean负责启动定时任务 -->  
  8.    <bean class="org.springframework.scheduling.timer.TimerFactoryBean">  
  9.         <property name="scheduledTimerTasks">  
  10.             <list>  
  11.                 <ref bean="scheduleReportTask"/><!-- 定时器列表 -->  
  12.             </list>  
  13.         </property>  
  14.     </bean>  

 

 

[java] view plain copy
  1. package cn.vicky.web.action.battle.timmer;  
  2.   
  3. import java.util.TimerTask;  
  4.   
  5. import javax.annotation.Resource;  
  6.   
  7. import org.springframework.stereotype.Component;  
  8.   
  9. import cn.vicky.model.po.Battle;  
  10. import cn.vicky.service.battle.BattleService;  
  11.   
  12. @Component("battleTimerTask")  
  13. public class BattleTimerTask extends TimerTask {  
  14.   
  15.     @Resource  
  16.     private BattleService battleService;  
  17.   
  18.     @Override  
  19.     public void run() {  
  20.         for (Battle battle : battleService.findAll()) {  
  21.             if (battle.isBegin()) {  
  22.                 System.out.println(battle.getTeamID());  
  23.                 System.out.println(battle.getTargetTeamID());  
  24.                 System.out.println(battle.getTargetPlayerID());  
  25.                 System.out.println(battle.getBeginTime());  
  26.                 System.out.println(battle.getTime());  
  27.                 System.out.println("----------");  
  28.                 battleService.delete(battle.getId());  
  29.             }  
  30.         }  
  31.     }  
  32.   
  33. }  
0
0
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值