Class TimeConstrained

java.lang.Object
ubc.team09.search.TimeConstrained
Direct Known Subclasses:
AlphaBeta

public class TimeConstrained extends Object
This class should be extended if you want to impose a time constraint on some process. To use it,
  1. use setTimeLimit(int) to set the time limit.
  2. use startTimer() to start the countdown.
  3. whenever you need to check the time limit, use checkTimeOccasionally() or checkTime(). Either of these methods will throw an exception if the time limit is expired. The former will only actually check the time once every ~1000 calls.
  • Constructor Details

    • TimeConstrained

      public TimeConstrained()
  • Method Details

    • setTimeLimit

      public void setTimeLimit(int seconds)
      Sets a time constraint on the process.
    • setTimeLimitMs

      public void setTimeLimitMs(long milliseconds)
      Sets a time constraint on the process.
    • startTimer

      protected void startTimer()
      Begins the timer.
    • checkTime

      protected void checkTime() throws TimeoutException
      Throws a TimeoutException if the timer is expired.
      Throws:
      TimeoutException
    • checkTimeOccasionally

      protected void checkTimeOccasionally() throws TimeoutException
      Once every ~1000 calls, this function will check the time and throw a TimeoutException if the timer is expired.
      Throws:
      TimeoutException