Java EE Singleton Scheduled Task Executed twice

半城伤御伤魂 提交于 2019-12-12 02:38:15

问题


I want to execute two tasks on scheduled time (23:59 CET and 08:00 CET). I have created an EJB singleton bean that maintains those methods:

@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.

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?


回答1:


I solved the problem with specifying scheduled time with server time (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.




回答2:


I had the same problem with TomEE plume 7.0.4. In my case the solution was to change @Singleton to @Stateless.



来源:https://stackoverflow.com/questions/19489568/java-ee-singleton-scheduled-task-executed-twice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!