tomcat参数引发后台建立影子任务
所谓后台影子任务
是在程序设置的自动&定时任务运行过程当中同一个任务启动了两次,对,两次,不多不少,就在那里。
第一次任务开始后第二次任务(不该存在的)时隔差不多30s-50s便开始执行。
Spring注解关键字Scheduled定时任务
代码:@Scheduled(fixedDelay = 1000 * 60 * 10)
任务是每隔10分钟执行一次。
问题已经解决了,当时看数据情况是这样的,用excel模拟一下任务日志表。
http://img.blog.csdn.net/20161024150717095?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
不难看出,任务ID 1、3、5 是每个10分钟执行一次的任务,可是任务ID2、4、6是什么鬼?
难道是服务器tomcat老进程没关掉,导致任务线程重复?
可是每次都kill掉tomcat了,并且重启多次tomcat,进程没杀掉也应该很多任务才对,为什么人家还是这么“成双成对”?
其实任务线程重复这个思路没有问题,
Google一下:“Quartz job runs twice when deployed on tomcat ”
tomcat配置中有此两个参数引起注意:
http://img.blog.csdn.net/20161024150803362?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
大体意思是参数默认为true,deploy发布则自动启动。
Stackflow中老外的解释是:
Whenusingautomatic 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 webapplication 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 applicationswill each bedeployed twice, and that may cause problems for the
applications.
deploy自启动一次+startup启动一次,果然是tomcat配置默认参数导致的重复任务。
解决方法
找到tomcatserver.xml文件,修改如下:
Host name="localhost"
deployOnStartup="false"
appBase="webapps"
unpackWARs="false"
重新启动tomcat,任务日志表如下:
http://img.blog.csdn.net/20161024150750372?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
一切都是那么自然……
页:
[1]