tomcat参数引发后台建立影子任务


所谓后台影子任务

是在程序设置的自动&定时任务运行过程当中同一个任务启动了两次,对,两次,不多不少,就在那里。

第一次任务开始后第二次任务(不该存在的)时隔差不多30s-50s便开始执行。


Spring注解关键字Scheduled定时任务

代码:@Scheduled(fixedDelay = 1000 * 60 * 10)

任务是每隔10分钟执行一次。

问题已经解决了,当时看数据情况是这样的,用excel模拟一下任务日志表。





不难看出,任务ID 1、3、5 是每个10分钟执行一次的任务,可是任务ID  2、4、6是什么鬼?

 

难道是服务器tomcat老进程没关掉,导致任务线程重复?

可是每次都kill掉tomcat了,并且重启多次tomcat,进程没杀掉也应该很多任务才对,为什么人家还是这么“成双成对”?

 

其实任务线程重复这个思路没有问题,

Google一下:“Quartz job runs twice when deployed on tomcat ”


 tomcat配置中有此两个参数引起注意:

 

大体意思是参数默认为true,deploy发布则自动启动。

Stackflow中老外的解释是:

Whenusing automatic deployment, the docBase defined by an XML Context file shouldbe outside of the appBase directory. If this is not the case, difficulties maybe experienced deploying the web application or the application may be deployedtwice. The deployIgnore attribute can be used to avoid this situation.

Finally, note that if you are defining contexts explicitly inserver.xml, you should probably turn off automatic application deployment orspecify deployIgnore carefully. Otherwise, the web applications will each bedeployed twice, and that may cause problems for the applications.


deploy自启动一次+startup启动一次,果然是tomcat配置默认参数导致的重复任务。

 

解决方法

找到tomcat  server.xml文件,修改如下:

Host name="localhost" 
        deployOnStartup="false"  

        appBase="webapps" 
        unpackWARs="false" 




重新启动tomcat,任务日志表如下:


一切都是那么自然……


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值