title: How do i put a limit on TimerTask rather than having it run forever?
body: <p>I'm using the timer utility to repeatedly post output of a code. Right now I have it set to repeat nonstop on a 1 second interval. How could I change this to instead repeat until a time limit set by the user is reached?</p>
  
  <pre><code>//Create a new timer
  Timer timer = new Timer();
  static int interval = 1000; //Interval of timer in milliseconds
  //Set the timer to start in 1 second and to go every certain amount of  milliseconds.
  timer.scheduleAtFixedRate(TimerClass.timertask, 1000, interval);
  </code></pre>