项目之前用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
“
问题解决。