Package es.urjc.etsii.grafo.util
Class TimeControl
java.lang.Object
es.urjc.etsii.grafo.util.TimeControl
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 Summary
Modifier and TypeMethodDescriptionstatic boolean
Is the time control enabled?static boolean
isTimeUp()
Check if we should end.static long
Get remaining timestatic void
remove()
Remove time restrictions for the current threadstatic void
setMaxExecutionTime
(long time, TimeUnit unit) Set max execution time.static void
start()
Start counting time
-
Method Details
-
setMaxExecutionTime
Set max execution time. Example:setMaxExecutionTime(5, TimeUnit.SECONDS);
- Parameters:
time
- time quantityunit
- 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
-