title: How do I schedule a task to run at periodic intervals?
body: <p>I was trying some codes to implement a scheduled task and came up with these codes .</p>
  
  <pre><code>import java.util.*;
  
  class Task extends TimerTask {
  
  
      int count = 1;
  
      // run is a abstract method that defines task performed at scheduled time.
      public void run() {
          System.out.println(count+" : Mahendra Singh");
          count++;
      }
  }
  
  class TaskScheduling {
  
     public static void main(String[] args) {
         Timer timer = new Timer();
  
  
         // Schedule to run after every 3 second(3000 millisecond)
         timer.schedule( new Task(), 3000);   
     }
  }
  </code></pre>
  
  <p>My output :</p>
  
  <pre><code>1  :  Mahendra Singh
  </code></pre>
  
  <p>I expected the compiler to print a series of Mahendra Singh at periodic interval of 3 s but despite waiting for around 15 minutes, I get only one output...How do I solve this out?</p>