Class TimeUtils


  • public class TimeUtils
    extends Object
    Various utilities for waiting some time.
    • Field Detail

      • SECOND_IN_MILLIS

        public static final long SECOND_IN_MILLIS
        Constant for the number of milliseconds per second: 1000.
        See Also:
        Constant Field Values
      • MINUTE_IN_SECONDS

        public static final long MINUTE_IN_SECONDS
        Constant for the number of seconds per minute: 60.
        See Also:
        Constant Field Values
      • HOUR_IN_MINUTES

        public static final long HOUR_IN_MINUTES
        Constant for the number of minutes per hour: 60.
        See Also:
        Constant Field Values
      • DAY_IN_HOURS

        public static final long DAY_IN_HOURS
        Constant for the number of hours per day: 24.
        See Also:
        Constant Field Values
      • WEEK_IN_DAYS

        public static final long WEEK_IN_DAYS
        Constant for the number of days per week: 7.
        See Also:
        Constant Field Values
    • Constructor Detail

      • TimeUtils

        public TimeUtils()
    • Method Detail

      • exponentialBackoffSleep

        public static void exponentialBackoffSleep​(int attempt)
        Sleep for an exponentially backing off amount of time, in milliseconds. Thus the first attempt will sleep for 1 ms, the second for 2, the third for 4, etc.
        Parameters:
        attempt - The attempt number, which is the log2 of the number of milliseconds spent asleep.
      • exponentialBackoffSleep

        public static void exponentialBackoffSleep​(int attempt,
                                                   int timeunit)
        Sleep for an exponentially backing off amount of time. The mode describes the unit of time as defined by @see java.util.Calendar
        Parameters:
        attempt - The attempt number, which is the log2 of the number of timeunits spent asleep.
        timeunit - the specified timeunit in miliseconds
        Throws:
        ArgumentNotValid - if timeunit is unsupported.
      • readableTimeInterval

        public static String readableTimeInterval​(long millis)
        Method for translating a time in milliseconds to a human readable String. E.g. the argument "604800000" should result in "7 days".
        Parameters:
        millis - The amount of milliseconds.
        Returns:
        The human readable string.