9

Can any one please explain about timing defined in lockAtLeastFor and lockAtMostFor. what is PT1M45S and what other parameters it can accept.

  @Scheduled(cron = "0 0/2 * * * *")
  @SchedulerLock(name = "TaskScheduler_scheduledTask", lockAtLeastFor = "PT1M45S", lockAtMostFor = "PT2M")
  public void performJob()
  {
     System.out.println("executed");
  }
Kim
  • 305
  • 1
  • 3
  • 14

4 Answers4

14

That is the ISO-8601 duration format. The P stands for period and is (optionally) followed by a duration in years (Y), months (M), weeks (W) and days (D). The T stands for time, and is followed by one or more of hours (H), minutes (M) and (fractional) seconds (S).

See also the javadoc of Duration.parse. The duration format supported by Java has no support for Y, M and W as specified in ISO-8601, but instead uses a simplified format like PnDTnHnMn.nS.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
1

This is the ISO 8601 format for duration.

It seems that you are using ShedLock. According to the doc, it can accept duration in ms.

/** * The lock will be held at least for X millis. Can be used if you really need to execute the task * at most once in given period of time. If the duration of the task is shorter than clock difference between nodes, the task can * be theoretically executed more than once (one node after another). By setting this parameter, you can make sure that the * lock will be kept at least for given period of time. */

long lockAtLeastFor() default -1;

ggr
  • 294
  • 1
  • 9
0

The documentation states:

Can be either time with suffix like 10s or ISO8601 duration as described in {@link java.time.Duration#parse(CharSequence)}, for example PT30S.

Michael Kreutz
  • 1,216
  • 6
  • 9
0

It's specified in ShedLock documentation

Duration specification

  • duration+unit - 1s, 5ms, 5m, 1d (Since 4.0.0)
  • duration in ms - 100 (only Spring integration)
  • ISO-8601 - PT15M (see Duration.parse() documentation)

https://github.com/lukas-krecan/ShedLock#duration-specification

Lukas
  • 13,606
  • 9
  • 31
  • 40