简体   繁体   English

Java EE Singleton计划任务执行两次

[英]Java EE Singleton Scheduled Task Executed twice

I want to execute two tasks on scheduled time (23:59 CET and 08:00 CET). 我想在计划的时间(欧洲中部时间23:59和欧洲中部时间08:00)执行两个任务。 I have created an EJB singleton bean that maintains those methods: 我创建了一个维护这些方法的EJB单例bean:

@Singleton
public class OfferManager {

    @Schedule(hour = "23", minute = "59", timezone = "CET")
    @AccessTimeout(value = 0) // concurrent access is not permitted
    public void fetchNewOffers() {
        Logger.getLogger(OfferManager.class.getName()).log(Level.INFO, "Fetching new offers started");

        // ...

        Logger.getLogger(OfferManager.class.getName()).log(Level.INFO, "Fetching new offers finished");
    }

    @Schedule(hour="8", minute = "0", timezone = "CET")
    public void sendMailsWithReports() {
        Logger.getLogger(OfferManager.class.getName()).log(Level.INFO, "Generating reports started");

        // ...

        Logger.getLogger(OfferManager.class.getName()).log(Level.INFO, "Generating reports finished");
    }
}

The problem is that both tasks are executed twice. 问题是两个任务都执行两次。 The server is WildFly Beta1, configured in UTC time. 该服务器为WildFly Beta1,以UTC时间配置。

Here are some server logs, that might be useful: 以下是一些服务器日志,可能有用:

2013-10-20 11:15:17,684 INFO  [org.jboss.as.server] (XNIO-1 task-7) JBAS018559: Deployed "crawler-0.3.war" (runtime-name : "crawler-0.3.war")
2013-10-20 21:59:00,070 INFO  [com.indeed.control.OfferManager] (EJB default - 1) Fetching new offers started
....
2013-10-20 22:03:48,608 INFO  [com.indeed.control.OfferManager] (EJB default - 1) Fetching new offers finished
2013-10-20 23:59:00,009 INFO  [com.indeed.control.OfferManager] (EJB default - 2) Fetching new offers started
....
2013-10-20 23:59:22,279 INFO  [com.indeed.control.OfferManager] (EJB default - 2) Fetching new offers finished

What might be the cause of such behaviour? 这种行为可能是什么原因?

I solved the problem with specifying scheduled time with server time (UTC). 我用服务器时间(UTC)指定计划时间解决了问题。 So 所以

@Schedule(hour = "23", minute = "59", timezone = "CET")

was replaced with: 被替换为:

@Schedule(hour = "21", minute = "59")

I don't know the cause of such beahaviour, maybe the early release of Wildfly is the issue. 我不知道这种行为的原因,也许是Wildfly的早期发行才是问题所在。

I had the same problem with TomEE plume 7.0.4. 我在TomEE plume 7.0.4中遇到了相同的问题。 In my case the solution was to change @Singleton to @Stateless . 在我的情况下,解决方案是将@Singleton更改为@Stateless

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM