EJB3计划无法正常工作

时间:2018-01-03 12:46:44

标签: java java-ee timer ejb wildfly-11

我一直在关注example of Adam Bean做计时器,但它没有正常工作。我创建了一个@Singleton EJB,其方法使用@Schedule进行了注释。该应用程序部署到野生动物11.我有两个问题。首先,我的计时器每秒记录一次,而不是每分钟记录一次。第二个问题是,每次触发时间时,都会收到错误消息。

有人可以给我一个提示吗,我做错了什么?也许我只是盲目无法看到它。

我的课程:

import javax.ejb.Schedule;
import javax.ejb.Singleton;
import java.util.logging.Logger;

@Singleton
public class DeviceTrackerCronJob {

    private static final Logger LOG = Logger.getLogger(DeviceTrackerCronJob.class.getName());

    private long counter;

@Schedule(second = "*", minute = "*/1", hour = "*", info = "Every Minute!")
public void execute() {
    LOG.info("### --- FAKING SOME CONTENT " + counter++);
    }
}

我得到的信息是:

  

12:42:03,025 INFO [de.klemensmorbe.tracking.DeviceTrackerCronJob](EJB default - 1)### --- FAKING SOME CONTENT 575   12:42:04,040 ERROR [org.jboss.as.ejb3.timer](EJB默认值 - 1)WFLYEJB0020:调用计时器超时时出错:[id = a797d1ca-e550-41e4-bfe7-46066f7b24b3 timedObjectId = web.web.DeviceTrackerCronJob auto-timer?:false persistent?:true timerService =org.jboss.as.ejb3.timerservice.TimerServiceImpl@c39b6bb initialExpiration = null intervalDuration(in milli sec)= 0 nextExpiration = Wed Jan 03 12:42:05 UTC 2018 timerState = IN_TIMEOUT info = null]:java.lang.RuntimeException:WFLYEJB0343:无法调用超时方法,因为方法null不是超时方法           在org.jboss.as.ejb3 // org.jboss.as.ejb3.timerservice.TimedObjectInvokerImpl.callTimeout(TimedObjectInvokerImpl.java:83)           在org.jboss.as.ejb3 // org.jboss.as.ejb3.timerservice.TimedObjectInvokerImpl.callTimeout(TimedObjectInvokerImpl.java:109)           在org.jboss.as.ejb3 // org.jboss.as.ejb3.timerservice.CalendarTimerTask.invokeBeanMethod(CalendarTimerTask.java:66)           在org.jboss.as.ejb3 // org.jboss.as.ejb3.timerservice.CalendarTimerTask.callTimeout(CalendarTimerTask.java:53)           在org.jboss.as.ejb3 // org.jboss.as.ejb3.timerservice.TimerTask.run(TimerTask.java:160)           在org.jboss.as.ejb3 // org.jboss.as.ejb3.timerservice.TimerServiceImpl $ Task $ 1.run(TimerServiceImpl.java:1220)           在org.wildfly.extension.request-controller // org.wildfly.extension.requestcontroller.RequestController $ QueuedTask $ 1.run(RequestController.java:497)           在java.base / java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)           at java.base / java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:641)           在java.base / java.lang.Thread.run(Thread.java:844)           在org.jboss.threads // org.jboss.threads.JBossThread.run(JBossThread.java:320)

     

12:42:04,041 INFO [org.jboss.as.ejb3.timer](EJB默认值 - 1)WFLYEJB0021:计时器:[id = a797d1ca-e550-41e4-bfe7-46066f7b24b3 timedObjectId = web.web.DeviceTrackerCronJob auto -timer ?: false persistent?:true timerService =org.jboss.as.ejb3.timerservice.TimerServiceImpl@c39b6bb initialExpiration = null intervalDuration(in milli sec)= 0 nextExpiration = Wed Jan 03 12:42:05 UTC 2018 timerState = IN_TIMEOUT将重试info = null]   12:42:04,041 INFO [org.jboss.as.ejb3.timer](EJB默认值 - 1)WFLYEJB0023:重试计时器超时:[id = a797d1ca-e550-41e4-bfe7-46066f7b24b3 timedObjectId = web.web.DeviceTrackerCronJob auto -timer ?: false persistent?:true timerService =org.jboss.as.ejb3.timerservice.TimerServiceImpl@c39b6bb initialExpiration = null intervalDuration(in milli sec)= 0 nextExpiration = Wed Jan 03 12:42:05 UTC 2018 timerState = IN_TIMEOUT信息= NULL]   12:42:04,042 ERROR [org.jboss.as.ejb3.timer](EJB默认值 - 1)WFLYEJB0022:重试计时器超时时出错:[id = a797d1ca-e550-41e4-bfe7-46066f7b24b3 timedObjectId = web.web。 DeviceTrackerCronJob auto-timer?:false persistent?:true timerService =org.jboss.as.ejb3.timerservice.TimerServiceImpl@c39b6bb initialExpiration = null intervalDuration(in milli sec)= 0 nextExpiration = Wed Jan 03 12:42:05 UTC 2018 timerState = RETRY_TIMEOUT info = null]:java.lang.RuntimeException:WFLYEJB0343:无法调用超时方法,因为方法null不是超时方法           在org.jboss.as.ejb3 // org.jboss.as.ejb3.timerservice.TimedObjectInvokerImpl.callTimeout(TimedObjectInvokerImpl.java:83)           在org.jboss.as.ejb3 // org.jboss.as.ejb3.timerservice.TimedObjectInvokerImpl.callTimeout(TimedObjectInvokerImpl.java:109)           在org.jboss.as.ejb3 // org.jboss.as.ejb3.timerservice.CalendarTimerTask.invokeBeanMethod(CalendarTimerTask.java:66)           在org.jboss.as.ejb3 // org.jboss.as.ejb3.timerservice.CalendarTimerTask.callTimeout(CalendarTimerTask.java:53)           在org.jboss.as.ejb3 // org.jboss.as.ejb3.timerservice.TimerTask.retryTimeout(TimerTask.java:234)           在org.jboss.as.ejb3 // org.jboss.as.ejb3.timerservice.TimerTask.run(TimerTask.java:168)           在org.jboss.as.ejb3 // org.jboss.as.ejb3.timerservice.TimerServiceImpl $ Task $ 1.run(TimerServiceImpl.java:1220)           在org.wildfly.extension.request-controller // org.wildfly.extension.requestcontroller.RequestController $ QueuedTask $ 1.run(RequestController.java:497)           在java.base / java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)           at java.base / java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:641)           在java.base / java.lang.Thread.run(Thread.java:844)           在org.jboss.threads // org.jboss.threads.JBossThread.run(JBossThread.java:320)

2 个答案:

答案 0 :(得分:2)

  

我的计时器每秒记录一次,而不是每分钟记录一次。

然后将第二个设置为应该运行的第二分钟。如果您希望它在12:00:00运行,那么在12:01:00(即每分钟的第二个0)运行,然后使用 var url = " https://www.googleapis.com/calendar/v3/users/me/calendarList"; var client = Ti.Network.createHTTPClient({ // function called when the response data is available onload : function(e) { Ti.API.info("users calendars: " + JSON.stringify(this.responseText)); alert('success'); }, // function called when an error occurs, including a timeout onerror : function(e) { Ti.API.debug(e.error); alert('error'); }, timeout : 5000 // in milliseconds }); // Prepare the connection. client.open("GET", url); // Send the request. client.send();

您可能还希望将持久性设置为false,除非您希望服务器在某些时候出现故障时赶上错过的时间表。

我不确定你为什么会收到超时错误。

答案 1 :(得分:1)

感谢您的建议。我修复了计时器并用于带锁的EJB。问题是(我认为),计时器不等待其他计时器完成。我的代码现在看起来像this example(3.具有固定延迟的计划任务)。