SSM框架 定时器会执行两次的原因

前两天做项目,会有结算,结算是晚上凌晨定时任务开始结算,本人采用的是Quertz,具体的方法如下:

 

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd ">
    <!--class是定时任务的实现类的路径-->
    <bean id="AutoTask" class="com.test.bill.bms.task.ArticleAutoTask"></bean>
    <bean id="AutoTaskJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <property name="targetObject" ref="AutoTask"/>
        <property name="targetMethod" value="execute"/>
        <property name="concurrent" value="false"/>
    </bean>
    <bean id="AutoTaskJobTrigger"
          class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
        <property name="jobDetail">
            <ref bean="AutoTaskJob"/>
        </property>
        <property name="cronExpression">
            <!--晚上0点10分-->
            <value>0 10 0 * * ?</value>
        </property>
    </bean>
    <bean name="startQuertz" lazy-init="false" autowire="no"
          class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="triggers">
            <list>
                <ref bean="AutoTaskJobTrigger"/>
            </list>
        </property>
    </bean>
</beans>

当时我的项目在服务器上面的环境是Tomcat,将项目打包成var包,第二天查数据库,发现定时任务直接运行了两次,里面的insert数据全部都添加了两条,即使我在前面有是否重复判断,直接绕过我的判断!!

后来查询各种百度,最终找到了原因,是因为默认的Tomcat配置要进行修改。

默认的tomcat配置server.xml是这样的

<Host name="localhost"  appBase="webapps"

            unpackWARs="true" autoDeploy="true">


        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->
        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log." suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

      </Host>

将上面的Host节点的代码改为下面:

本文章为博主原创文章,未经允许禁止转载!

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值