3

I use an openejb @Resource TimerService (which injects org.apache.openejb.core.timer.TimerServiceImpl I think) to set a recurring task to each second.

timerService.createCalendarTimer(new ScheduleExpression()
                                    .hour("*"),
                                    .minute("*"),
                                    .second("1"),
                                    new TimerConfig("timerName",false)
                                    );

Initially, the timeouts occure more or less each second, but with time the reliability deteriorates and after several days the deltas between the calls look someting like that:

    delta [seconds]     number of occurences
    ----------------------------------------------
    0                   18057
    1                   35084
    2                   2509
    3                   4668
    4                   1869
    5                   2093
    6                   632
    7                   376
    8                   697
    9                   93
    10                  6
    11                  3
    15                  2
    16                  1
    18                  1
    19                  1
    20                  3
    22                  2
    25                  2
    26                  2
    31                  2
    33                  1
    34                  1
    38                  1

The function called is not blocking, I don't get any "UnableToAquireLock" exceptions.

How can I ensure that not more then two seconds pass between two sequential calls for the function?

alex440
  • 1,647
  • 3
  • 20
  • 35
  • A couple of questions about usage: 1. An enterprise bean usually creates a timer within a transaction. If this transaction is rolled back, the timer creation also is rolled back. Similarly, if a bean cancels a timer within a transaction that gets rolled back, the timer cancellation is rolled back. In this case, the timer’s duration is reset as if the cancellation had never occurred. Can you check this? – Henry Aloni Jan 10 '18 at 07:34
  • 2. Are you using a Scheduled bean with one method decorated with Timeout annotation? 3. Can you consider using a simple timer using timerService.createTimer(...) instead of a timerService.createCalendarTimer (see ref here https://docs.oracle.com/javaee/6/tutorial/doc/bnboy.html#bnbpe) – Henry Aloni Jan 10 '18 at 07:38
  • Can you post your full example code? – Jonathan S. Fisher Feb 22 '21 at 21:33

0 Answers0