NutzCN Logo
问答 我用的nutzwk框架,执行的后台任务总是被执行两次。
发布于 225天前 作者 qq_df433f5d 277 次浏览 复制 上一个帖子 下一个帖子
标签: nutzwk

我用的nutzwk框架,执行的后台任务总是被执行两次,也没搞明白哪里的原因。

@IocBean
public class UpdateAnnualJob implements Job {

    private static final Log log = Logs.get();
    @Inject
    protected Dao dao;

    public void execute(JobExecutionContext context) throws JobExecutionException {
        try {
            JobDataMap data = context.getJobDetail().getJobDataMap();
            String taskId = context.getJobDetail().getKey().getName();
......
......
业务逻辑
......
        }
    }

2020-01-02 23:58:00,005 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'updateAnnualJob'<class cn.wizzer.app.web.commons.quartz.job.UpdateAnnualJob>
2020-01-02 23:58:00,005 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'updateAnnualJob'<class cn.wizzer.app.web.commons.quartz.job.UpdateAnnualJob>
2020-01-02 23:58:00,005 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:177) DEBUG - 	 >> Load definition name=updateAnnualJob
2020-01-02 23:58:00,005 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:177) DEBUG - 	 >> Load definition name=updateAnnualJob
2020-01-02 23:58:00,005 org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:169) DEBUG - Found IocObject(updateAnnualJob) in AnnotationIocLoader(packages=[cn.wizzer])
2020-01-02 23:58:00,005 org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:169) DEBUG - Found IocObject(updateAnnualJob) in AnnotationIocLoader(packages=[cn.wizzer])
2020-01-02 23:58:00,005 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:209) DEBUG - 	 >> Make...'updateAnnualJob'<class cn.wizzer.app.web.commons.quartz.job.UpdateAnnualJob>
2020-01-02 23:58:00,005 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:209) DEBUG - 	 >> Make...'updateAnnualJob'<class cn.wizzer.app.web.commons.quartz.job.UpdateAnnualJob>
2020-01-02 23:58:00,005 cn.wizzer.app.web.commons.plugin.PluginAopConfigure.getInterceptorPairList(PluginAopConfigure.java:33) DEBUG - skip -- cn.wizzer.app.web.commons.quartz.job.UpdateAnnualJob
2020-01-02 23:58:00,005 cn.wizzer.app.web.commons.plugin.PluginAopConfigure.getInterceptorPairList(PluginAopConfigure.java:33) DEBUG - skip -- cn.wizzer.app.web.commons.quartz.job.UpdateAnnualJob
2020-01-02 23:58:00,005 org.nutz.ioc.aop.impl.DefaultMirrorFactory.getMirror(DefaultMirrorFactory.java:70) DEBUG - Load class cn.wizzer.app.web.commons.quartz.job.UpdateAnnualJob without AOP
2020-01-02 23:58:00,005 org.nutz.ioc.aop.impl.DefaultMirrorFactory.getMirror(DefaultMirrorFactory.java:70) DEBUG - Load class cn.wizzer.app.web.commons.quartz.job.UpdateAnnualJob without AOP
2020-01-02 23:58:00,021 org.nutz.ioc.impl.ScopeContext.save(ScopeContext.java:64) DEBUG - Save object 'updateAnnualJob' to [app] 
2020-01-02 23:58:00,021 org.nutz.ioc.impl.ScopeContext.save(ScopeContext.java:64) DEBUG - Save object 'updateAnnualJob' to [app] 
2020-01-02 23:58:00,021 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'dao'<interface org.nutz.dao.Dao>
2020-01-02 23:58:00,021 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'dao'<interface org.nutz.dao.Dao>
2020-01-02 23:58:00,021 org.quartz.core.JobRunShell.run(JobRunShell.java:201) DEBUG - Calling execute on job e0b4be177c584c528a378cb881a3457d.e0b4be177c584c528a378cb881a3457d
2020-01-02 23:58:00,021 org.quartz.core.JobRunShell.run(JobRunShell.java:201) DEBUG - Calling execute on job e0b4be177c584c528a378cb881a3457d.e0b4be177c584c528a378cb881a3457d
13 回复

不是log打了两遍,是代码确实被执行了两遍。看代码也没什么问题,晕了。

cron设置是0 58 23 * * ?,每天晚上23点58执行。同时执行两遍。我查了历史帖子,我的tomcat里host只有一个,搞不清楚,头大了。
大神救我!

其他日志不是两遍?log4j配置问题吧

其他日志是正常的。

多贴点相邻的日志给大神参考

2020-01-02 23:57:56,162 cn.wizzer.app.web.commons.processor.LogTimeProcessor.process(LogTimeProcessor.java:26) DEBUG - [POST]URI=/open/weixin/api/ee3907ae917b4bfc9f9164de37a24074 32ms
2020-01-02 23:57:56,380 org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:101) DEBUG - Found mapping for [POST] path=/api/v1/ins/products : ApiController.getProducts(ApiController.java:243)
2020-01-02 23:57:56,380 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'shiroUtil'<class cn.wizzer.framework.util.ShiroUtil>
2020-01-02 23:57:56,380 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'dateUtil'<class cn.wizzer.framework.util.DateUtil>
2020-01-02 23:57:56,380 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'stringUtil'<class cn.wizzer.framework.util.StringUtil>
2020-01-02 23:57:56,380 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'apiController'<class cn.wizzer.app.web.modules.controllers.front.wx.ApiController>
2020-01-02 23:57:56,380 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - SELECT * FROM ins_product  ORDER BY location DESC  
2020-01-02 23:57:56,396 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - SELECT * FROM ins_channel_rate  WHERE channelId=?
    | 1 |
    |--|
    |  |
  For example:> "SELECT * FROM ins_channel_rate  WHERE channelId=''"
2020-01-02 23:57:56,396 cn.wizzer.app.web.commons.processor.LogTimeProcessor.process(LogTimeProcessor.java:26) DEBUG - [POST]URI=/api/v1/ins/products 16ms
2020-01-02 23:58:00,005 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'updateAnnualJob'<class cn.wizzer.app.web.commons.quartz.job.UpdateAnnualJob>
2020-01-02 23:58:00,005 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'updateAnnualJob'<class cn.wizzer.app.web.commons.quartz.job.UpdateAnnualJob>
2020-01-02 23:58:00,005 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:177) DEBUG - 	 >> Load definition name=updateAnnualJob
2020-01-02 23:58:00,005 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:177) DEBUG - 	 >> Load definition name=updateAnnualJob
2020-01-02 23:58:00,005 org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:169) DEBUG - Found IocObject(updateAnnualJob) in AnnotationIocLoader(packages=[cn.wizzer])
2020-01-02 23:58:00,005 org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:169) DEBUG - Found IocObject(updateAnnualJob) in AnnotationIocLoader(packages=[cn.wizzer])

把quartz的日志调为debug

可能是两个quartz实例

怎么设置?我现在log4j就是debug级别。
是要在quartz.properties里设置吗?我没搜到相关的参数。
另外我发现线程池设置的是2,这个应该是并发数吧,不会同时执行两次吧。

org.quartz.threadPool.threadCount = 2

把这个也设置了。

log4j.logger.org.quartz.core.QuartzSchedulerThread=debug

看看 sys_task 表里有几条记录

sys_task里任务数只有一条。

log4j配置错误, 导致打印了2次日志, 整个配置文件贴出来

这个BUG 我也遇到过 估计是 Tomcat war包的问题
Tomcat 编译了 war 解压目录 也执行了
删除war包 应该能解决

添加回复
请先登陆
回到顶部