spring3.0自带的定时任务重复执行两次

在做公司的项目,使用spring3.0自动的定时任务,通过如下方式配置:

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

</task:scheduled-tasks>

本地使用tomcat和jboss部署,定时任务执行均正常,但上了linux测试及生产环境后,莫名的发现同一任务在同一时间被执行了两次,网上也搜集了大量资料,遇到类似问题的人也很多,逐一排查发现都是网上说的问题。最后发现项目中为了使用根目录可以直接访问系统,上线前在war包里加了jboss-web.xml配置文件,配置如下,导致job重复执行的真凶就是<context-root >/</context-root>,它会使web再重新加载一次,去掉之后就可以解决job重复执行的问题了。

<!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 2.3V2//EN" "http://www.jboss.org/j2ee/dtd/jboss-web_3_2.dtd">
   
<jboss-web>    
    <class-loading java2ClassLoadingCompliance="true">  
        <loader-repository>  
            com.example:archive= unique-archive-name  
            <loader-repository-config>  
                java2ParentDelegation=true  
            </loader-repository-config>  
        </loader-repository>  
    </class-loading>  
    <context-root >/</context-root>
    <virtual-host>api.********.cn</virtual-host>
    <virtual-host>192.168.1.202</virtual-host>
</jboss-web>
   

猜你喜欢

转载自blog.csdn.net/kongtong2004/article/details/49174005
今日推荐