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


所谓后台影子任务

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

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


Spring注解关键字Scheduled定时任务

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

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

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





扫描二维码关注公众号,回复: 1933675 查看本文章

不难看出,任务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,任务日志表如下:


一切都是那么自然……


猜你喜欢

转载自blog.csdn.net/u014756578/article/details/52874884