简体   繁体   中英

EJB3 schedule not working correctly

I've been following the example of Adam Bean to do a timer, but it doesn't work properly. I created an @Singleton EJB with a method which is annoted with @Schedule . The application is deployed to a wildfly 11. I have two problems here. The first is, that my timer logs every second, instead of every minute. The second problem is, that every time the time is triggered, I get an error message.

Could someone give me a hint, what do I do wrong? Maybe I'm just blind and cant see it.

My 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++);
    }
}

The message I get is:

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(CalendarT imerTask.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$1.run(TimerServiceImpl.java:1220) at org.wildfly.extension.request-controller//org.wildfly.extension.requestcontroller.RequestController$QueuedTask$1.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$1.run(TimerServiceImpl.java:1220) at org.wildfly.extension.request-controller//org.wildfly.extension.requestcontroller.RequestController$QueuedTask$1.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.

Then set the second to the second of minute when it should run. If you want it to run at 12:00:00, then 12:01:00 (ie at second 0 of each minute), then use second = "0" .

You probably also want persistent set to false, unless you want the server to catch up with the missed schedules if it's down at some point.

I'm not sure why you are getting the timeout error.

thanks for the advice. I fixed the timer and used to EJBs with locks. The problem was (what I think), that the timers don't wait for the other timers to be complete. My code looks now like in this example (3. Schedule Task with a Fixed Delay).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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