javaspring-bootscheduled-tasksschedulershedlock

Can anyone please explain about the timing mentioned in lockAtLeastFor = "PT1M45S", lockAtMostFor = "PT2M" what is PT here


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");
  }

Solution

  • 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.