EJB3 计划无法正常工作
EJB3 schedule not working correctly
我一直在跟着example of Adam Bean做一个计时器,但是它不能正常工作。我用一个用 @Schedule
注释的方法创建了一个 @Singleton
EJB。该应用程序部署到wildfly 11。我这里有两个问题。首先,我的计时器每秒记录一次,而不是每分钟一次。第二个问题是,每次触发时间,我都会收到一条错误消息。
谁能给我一个提示,我做错了什么?可能是我瞎了,看不到。
我的class:
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 default - 1) WFLYEJB0020: Error invoking timeout for timer: [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: Cannot invoke timeout method because method null is not a timeout method
at org.jboss.as.ejb3//org.jboss.as.ejb3.timerservice.TimedObjectInvokerImpl.callTimeout(TimedObjectInvokerImpl.java:83)
at org.jboss.as.ejb3//org.jboss.as.ejb3.timerservice.TimedObjectInvokerImpl.callTimeout(TimedObjectInvokerImpl.java:109)
at org.jboss.as.ejb3//org.jboss.as.ejb3.timerservice.CalendarTimerTask.invokeBeanMethod(CalendarTimerTask.java:66)
at org.jboss.as.ejb3//org.jboss.as.ejb3.timerservice.CalendarTimerTask.callTimeout(CalendarTimerTask.java:53)
at org.jboss.as.ejb3//org.jboss.as.ejb3.timerservice.TimerTask.run(TimerTask.java:160)
at org.jboss.as.ejb3//org.jboss.as.ejb3.timerservice.TimerServiceImpl$Task.run(TimerServiceImpl.java:1220)
at org.wildfly.extension.request-controller//org.wildfly.extension.requestcontroller.RequestController$QueuedTask.run(RequestController.java:497)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.base/java.lang.Thread.run(Thread.java:844)
at org.jboss.threads//org.jboss.threads.JBossThread.run(JBossThread.java:320)
12:42:04,041 INFO [org.jboss.as.ejb3.timer] (EJB default - 1) WFLYEJB0021: Timer: [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] will be retried
12:42:04,041 INFO [org.jboss.as.ejb3.timer] (EJB default - 1) WFLYEJB0023: Retrying timeout for timer: [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,042 ERROR [org.jboss.as.ejb3.timer] (EJB default - 1) WFLYEJB0022: Error during retrying timeout for timer: [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: Cannot invoke timeout method because method null is not a timeout method
at org.jboss.as.ejb3//org.jboss.as.ejb3.timerservice.TimedObjectInvokerImpl.callTimeout(TimedObjectInvokerImpl.java:83)
at org.jboss.as.ejb3//org.jboss.as.ejb3.timerservice.TimedObjectInvokerImpl.callTimeout(TimedObjectInvokerImpl.java:109)
at org.jboss.as.ejb3//org.jboss.as.ejb3.timerservice.CalendarTimerTask.invokeBeanMethod(CalendarTimerTask.java:66)
at org.jboss.as.ejb3//org.jboss.as.ejb3.timerservice.CalendarTimerTask.callTimeout(CalendarTimerTask.java:53)
at org.jboss.as.ejb3//org.jboss.as.ejb3.timerservice.TimerTask.retryTimeout(TimerTask.java:234)
at org.jboss.as.ejb3//org.jboss.as.ejb3.timerservice.TimerTask.run(TimerTask.java:168)
at org.jboss.as.ejb3//org.jboss.as.ejb3.timerservice.TimerServiceImpl$Task.run(TimerServiceImpl.java:1220)
at org.wildfly.extension.request-controller//org.wildfly.extension.requestcontroller.RequestController$QueuedTask.run(RequestController.java:497)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.base/java.lang.Thread.run(Thread.java:844)
at org.jboss.threads//org.jboss.threads.JBossThread.run(JBossThread.java:320)
my timer logs every second, instead of every minute.
然后在应该 运行 时将秒设置为分钟的秒数。如果您希望它在 12:00:00 处 运行,然后 12:01:00(即每分钟的第 0 秒),则使用 second = "0"
.
您可能还希望将持久性设置为 false,除非您希望服务器在某个时候出现故障时赶上错过的计划。
我不确定您为什么会收到超时错误。
感谢您的建议。我修复了计时器并习惯了带锁的 EJB。问题是(我认为),计时器不等待其他计时器完成。我的代码现在看起来像 this example(3. 以固定延迟安排任务)。
我一直在跟着example of Adam Bean做一个计时器,但是它不能正常工作。我用一个用 @Schedule
注释的方法创建了一个 @Singleton
EJB。该应用程序部署到wildfly 11。我这里有两个问题。首先,我的计时器每秒记录一次,而不是每分钟一次。第二个问题是,每次触发时间,我都会收到一条错误消息。
谁能给我一个提示,我做错了什么?可能是我瞎了,看不到。
我的class:
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 default - 1) WFLYEJB0020: Error invoking timeout for timer: [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: Cannot invoke timeout method because method null is not a timeout method at org.jboss.as.ejb3//org.jboss.as.ejb3.timerservice.TimedObjectInvokerImpl.callTimeout(TimedObjectInvokerImpl.java:83) at org.jboss.as.ejb3//org.jboss.as.ejb3.timerservice.TimedObjectInvokerImpl.callTimeout(TimedObjectInvokerImpl.java:109) at org.jboss.as.ejb3//org.jboss.as.ejb3.timerservice.CalendarTimerTask.invokeBeanMethod(CalendarTimerTask.java:66) at org.jboss.as.ejb3//org.jboss.as.ejb3.timerservice.CalendarTimerTask.callTimeout(CalendarTimerTask.java:53) at org.jboss.as.ejb3//org.jboss.as.ejb3.timerservice.TimerTask.run(TimerTask.java:160) at org.jboss.as.ejb3//org.jboss.as.ejb3.timerservice.TimerServiceImpl$Task.run(TimerServiceImpl.java:1220) at org.wildfly.extension.request-controller//org.wildfly.extension.requestcontroller.RequestController$QueuedTask.run(RequestController.java:497) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.base/java.lang.Thread.run(Thread.java:844) at org.jboss.threads//org.jboss.threads.JBossThread.run(JBossThread.java:320)
12:42:04,041 INFO [org.jboss.as.ejb3.timer] (EJB default - 1) WFLYEJB0021: Timer: [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] will be retried 12:42:04,041 INFO [org.jboss.as.ejb3.timer] (EJB default - 1) WFLYEJB0023: Retrying timeout for timer: [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,042 ERROR [org.jboss.as.ejb3.timer] (EJB default - 1) WFLYEJB0022: Error during retrying timeout for timer: [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: Cannot invoke timeout method because method null is not a timeout method at org.jboss.as.ejb3//org.jboss.as.ejb3.timerservice.TimedObjectInvokerImpl.callTimeout(TimedObjectInvokerImpl.java:83) at org.jboss.as.ejb3//org.jboss.as.ejb3.timerservice.TimedObjectInvokerImpl.callTimeout(TimedObjectInvokerImpl.java:109) at org.jboss.as.ejb3//org.jboss.as.ejb3.timerservice.CalendarTimerTask.invokeBeanMethod(CalendarTimerTask.java:66) at org.jboss.as.ejb3//org.jboss.as.ejb3.timerservice.CalendarTimerTask.callTimeout(CalendarTimerTask.java:53) at org.jboss.as.ejb3//org.jboss.as.ejb3.timerservice.TimerTask.retryTimeout(TimerTask.java:234) at org.jboss.as.ejb3//org.jboss.as.ejb3.timerservice.TimerTask.run(TimerTask.java:168) at org.jboss.as.ejb3//org.jboss.as.ejb3.timerservice.TimerServiceImpl$Task.run(TimerServiceImpl.java:1220) at org.wildfly.extension.request-controller//org.wildfly.extension.requestcontroller.RequestController$QueuedTask.run(RequestController.java:497) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.base/java.lang.Thread.run(Thread.java:844) at org.jboss.threads//org.jboss.threads.JBossThread.run(JBossThread.java:320)
my timer logs every second, instead of every minute.
然后在应该 运行 时将秒设置为分钟的秒数。如果您希望它在 12:00:00 处 运行,然后 12:01:00(即每分钟的第 0 秒),则使用 second = "0"
.
您可能还希望将持久性设置为 false,除非您希望服务器在某个时候出现故障时赶上错过的计划。
我不确定您为什么会收到超时错误。
感谢您的建议。我修复了计时器并习惯了带锁的 EJB。问题是(我认为),计时器不等待其他计时器完成。我的代码现在看起来像 this example(3. 以固定延迟安排任务)。