Class SchedulingUtils


  • public class SchedulingUtils
    extends java.lang.Object
    Class for helping calculate the offset for scheduling tasks. For example if you want a task to run at 10 minutes after the hour, every hour, you can use getDelayTillMinute(int) to calculate the initial delay needed when scheduling with SubmitterScheduler.scheduleAtFixedRate(Runnable, long, long), and then provide 1 hour in milliseconds for the "period".
    Since:
    3.5.0
    • Constructor Summary

      Constructors 
      Constructor Description
      SchedulingUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static long getDelayTillHour​(int hour, int minute)
      Call to calculate how many milliseconds until the provided time.
      static long getDelayTillMinute​(int minute)
      Call to calculate how many milliseconds until the provided minute.
      static int shiftLocalHourToUTC​(int hour)
      This will shift an hour from the local time zone to UTC.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SchedulingUtils

        public SchedulingUtils()
    • Method Detail

      • getDelayTillMinute

        public static long getDelayTillMinute​(int minute)
        Call to calculate how many milliseconds until the provided minute. If we are past the provided minute, it will be the milliseconds until we reach that minute with the NEXT hour.

        Because of use of Clock.lastKnownTimeMillis(), this calculation will only be accurate within about 100 milliseconds. Of course if provided to a scheduler, depending on it's work load that variation may be greater.

        Parameters:
        minute - Minute to calculate too, can not be negative and must be less than 60
        Returns:
        Time in milliseconds till that minute is reached
      • getDelayTillHour

        public static long getDelayTillHour​(int hour,
                                            int minute)
        Call to calculate how many milliseconds until the provided time. If we are past the provided hour/minute, it will be the milliseconds until we reach that time with the NEXT day.

        It is important to note that the time zone for this hour is UTC. If you want to use this for local time, just pass the hour through shiftLocalHourToUTC(int). This will convert a local time's hour to UTC so that it can be used in this invocation.

        Because of use of Clock.lastKnownTimeMillis(), this calculation will only be accurate within about 100 milliseconds. Of course if provided to a scheduler, depending on it's work load that variation may be greater.

        Parameters:
        hour - Hour in the 24 hour format, can not be negative and must be less than 24
        minute - Minute to calculate too, can not be negative and must be less than 60
        Returns:
        Time in milliseconds till provided time is reached
      • shiftLocalHourToUTC

        public static int shiftLocalHourToUTC​(int hour)
        This will shift an hour from the local time zone to UTC. This shift will take into account the current local state of daylight savings time. The primary usage of this is so that getDelayTillHour(int, int) can be used with a local time zone hour.
        Parameters:
        hour - Hour to be shifted in the local time zone in 24 hour format
        Returns:
        Hour shifted to the UTC time zone in 24 hour format