Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java EE6 Schedule Range

I'm required to have a schedule that runs every 5 minutes from 10 am to 5:45pm, how do I do this with the @Schedule annotation?

So far, I'm limited to the @Schedule(hour=10-18;minute=*/5), but they insist I should have it until 5:45pm not 6pm.

like image 887
Herupkhart Avatar asked Apr 10 '17 02:04

Herupkhart


1 Answers

As clearly stated in the documentation for @Schedule and @Schedules, you need to have two @Schedule annotations if you run two schedules - even if you don't like that fact.

Due to the cron-like limitations of having ranges only within individual elements (hours, minutes, seconds...), it's simply not posible to give that additional information of skipping the last two executions at *:50 and *:55 only at 5pm.

That said, you'd probably end up with something like

@Schedules({
   @Schedule(hour="10-16" minute="*/5"),
   @Schedule(hour="17" minute="0,5,10,15,20,25,30,35,40,45")
})

As you end up with schedule information into you sourcecode that way (even if it's in the form of an annotation) you could just as well run every five minutes and immediately return from the method if called after 5:49pm

like image 63
Jan Avatar answered Nov 09 '22 00:11

Jan