Quartz 报错,改用Spring task

项目之前用spring 3.0.6,quartz1.8.5,在tomcat下undeploy应用时,报错:

严重: The web application [/ROOT] appears to have started a thread named [genera
teSmsDataBean_Worker-10] but has failed to stop it. This is very likely to creat
e a memory leak.


上stackoverflow查了,有人提到一种解决办法

http://stackoverflow.com/questions/1827212/registering-a-shutdown-hook-in-spring-2-5


我没有试这种办法,因为我跟踪spring 的SchedulerFactoryBean 的destory方法,在redeploy应用时是有调用的。


后来又看到一篇文章:

http://forums.terracotta.org/forums/posts/list/3479.page

提到可能是tomcat的bug,要在SchedulerFactoryBean 的destory里面的shutdown方法后,加上sleep(1000)。


我比较懒,不想改源码,也不想复写一个factory。继续找办法解决。。。


网上有人说quartz2.0修复了这个问题,我查了spring的文档说,spring3.1.2支持quartz2.X了,于是很高兴的升级了。

结果按照spring的官方文档

http://static.springsource.org/spring/docs/3.1.2.RELEASE/spring-framework-reference/html/scheduling.html

里的配置,报错:


java.lang.IncompatibleClassChangeError: class org.springframework.scheduling.quartz.CronTriggerBean has interface org.quartz.CronTrigger as super class


这是因为quartz2把CronTrigger改成接口了,而spring里CronTriggerBean还把它当成一个基类。

看来spring的文档也很忽悠人啊。


再仔细看刚刚那个spring的文档,原来spring自己已经提供了 Task Execution and Scheduling 的支持。难怪对第三方的支持这么不给力了。

果断使用spring原生态支持,配置很简单:

<task:scheduled-tasks> 
        <task:scheduled ref="smsService" method="generateSmsData" cron="0 0/30 * * * ?" /> 
</task:scheduled-tasks> 

在xml前加上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-3.1.xsd
“


问题解决。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值