Search code examples
javajava-ee-6

ScheduleExpression and increments


I was experimenting with ScheduleExpression and noticed a strange behavior:

If I create a timer every 30 seconds with

scheduleExpression.second("*/30");

I get

[second=*/30;minute=*;hour=*;dayOfMonth=*;month=*;dayOfWeek=*;year=*;timezoneID=null;start=null;end=null]

and my timer is executed every 30 seconds (at :00 and :30) as expected. So far so good.

I then tried to do the same with minutes

scheduleExpression.minute("*/1");

and as expected I get

[second=*;minute=*/1;hour=*;dayOfMonth=*;month=*;dayOfWeek=*;year=*;timezoneID=null;start=null;end=null]

but my @Timeout method is called continuously. The code is exactly the same I am just changing the ScheduleExpression.

Is this a know issue? Or did I misinterpret the documentation and I have to set both

scheduleExpression.second(0);
scheduleExpression.minute("*/1");

Solution

  • From ScheduleExpression documentation it seems that you should call both methods (especially if you scheduled seconds before).

    Look at this:

    Example : ( minute = "∗/14", hour="1,2")
    

    They are setting both minutes and hours.