Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring scheduled fixedRateString as Duration

The @Scheduled documentation here states that the fixedRateString value can be the delay in milliseconds as a String value, e.g. a placeholder or a java.time.Duration compliant value. Meaning I can either write

@Scheduled(fixedRateString = "45s")

OR

@Scheduled(fixedRateString = "45000")

And it should be the same. However when I try to run it I get

Encountered invalid @Scheduled method 'updateWarmupInstances': Invalid fixedRateString value "45s" - cannot parse into long

So it this a mistake on Spring's part or am I doing something wrong ?

like image 270
Ben Avatar asked Dec 12 '18 00:12

Ben


2 Answers

To use the method @Scheduled(fixedRateString) for durations, you could use a String with the standard duration:

@Scheduled(fixedRateString = "PT45S")

The prefix PT is for ISO-8601 standard and in this example, it's mean the duration of 45 seconds.

Another example could be a duration of 1h:

@Scheduled(fixedRateString = "PT1H")
like image 81
Bruno Morais Avatar answered Sep 20 '22 14:09

Bruno Morais


You are looking at the return value of the method, not the input. The input can only be a String in milliseconds, but the return value is a value compliant with Duration.

like image 21
Erik Pragt Avatar answered Sep 20 '22 14:09

Erik Pragt