我想在计划的时间(欧洲中部时间23:59和欧洲中部时间08:00)执行两个任务。我创建了一个维护这些方法的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");
}
}
问题是两个任务都执行两次。该服务器为WildFly Beta1,以UTC时间配置。
以下是一些服务器日志,可能有用:
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
这种行为可能是什么原因?
最佳答案
我用服务器时间(UTC)指定计划时间解决了问题。
所以
@Schedule(hour = "23", minute = "59", timezone = "CET")
被替换为:
@Schedule(hour = "21", minute = "59")
我不知道这种行为的原因,也许是Wildfly的早期发行才是问题所在。
关于java - Java EE Singleton计划任务执行两次,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19489568/