Class TimeUtils


  • public class TimeUtils
    extends java.lang.Object
    Various utilities for waiting some time.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static long DAY_IN_HOURS
      Constant for the number of hours per day: 24.
      static long HOUR_IN_MINUTES
      Constant for the number of minutes per hour: 60.
      static long MINUTE_IN_SECONDS
      Constant for the number of seconds per minute: 60.
      static long SECOND_IN_MILLIS
      Constant for the number of milliseconds per second: 1000.
      static long WEEK_IN_DAYS
      Constant for the number of days per week: 7.
    • Constructor Summary

      Constructors 
      Constructor Description
      TimeUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void exponentialBackoffSleep​(int attempt)
      Sleep for an exponentially backing off amount of time, in milliseconds.
      static void exponentialBackoffSleep​(int attempt, int timeunit)
      Sleep for an exponentially backing off amount of time.
      static java.lang.String readableTimeInterval​(long millis)
      Method for translating a time in milliseconds to a human readable String.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 java.lang.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.