Class TimeControl

java.lang.Object
es.urjc.etsii.grafo.util.TimeControl

public class TimeControl extends Object
Tracks time usage across different threads. Long-running methods should frequently check if they are exceeding their time budget Once the budget has been consumed, they should return as soon as possible
  • Method Details

    • setMaxExecutionTime

      public static void setMaxExecutionTime(long time, TimeUnit unit)
      Set max execution time. Example:
       
       setMaxExecutionTime(5, TimeUnit.SECONDS);
      Parameters:
      time - time quantity
      unit - time unit (minutes, seconds, milliseconds, etc)
    • start

      public static void start()
      Start counting time
    • remove

      public static void remove()
      Remove time restrictions for the current thread
    • isTimeUp

      public static boolean isTimeUp()
      Check if we should end.
      Returns:
      true if the algorithm component should try to immediately end
    • remaining

      public static long remaining()
      Get remaining time
      Returns:
      time remaining in nanoseconds. If the time has elapsed, it will return a negative number indicating how much extra time has passed.
    • isEnabled

      public static boolean isEnabled()
      Is the time control enabled?
      Returns:
      true if enabled, false otherwise