title: Timer schedule vs scheduleAtFixedRate?
body: <pre><code>public class MyTimerTask extends TimerTask{
  
      @Override
      public void run() {
          int i = 0; 
          try {
              Thread.sleep(100000);
          } catch (InterruptedException e) {
              e.printStackTrace();
          }
          System.out.println("Run Me ~" + ++i);
          System.out.println("Test");
  
      }
  
  }
  
  Case 1 :-
      TimerTask task = new MyTimerTask();
      Timer timer = new Timer();
      timer.schedule(task, 1000,6000); // line 1
      System.out.println("End"); // here is bebug point. 
  </code></pre>
  
  <p>My Expectation of <code>schedule()</code> method (as per my understanding given in <code>javadocs</code> where each execution is scheduled once previous task execution is completed) 
  that two threads should be
  created after line 1. </p>
  
  <p>One for <code>timer</code> which spawns another thread for tasks. Once first task thread dies
  another will be created and son on. But at debug point , i just see one thread corresponding to <code>Timer</code>. Why
  not thread for tasks which implement <code>Runnable</code>?</p>
  
  <pre><code>Case 2 :-
  
      TimerTask task = new MyTimerTask();
      Timer timer = new Timer();
      timer.scheduleAtFixedRate(task, 1000,6000); // line 1
      System.out.println("End"); // here is bebug point. 
  </code></pre>
  
  <p>My Expectation of <code>scheduleAtFixedRate()</code> method(as per my understanding given in javadocs where  each execution is scheduled relative to the scheduled 
  execution time of the initial execution) that around 17 threads(dont pay much attention
  to 17. It can be more or less to that. But it should be greater than 2 ) should be
  created after line 1. </p>
  
  <p>One for <code>timer</code>  which should spawn  16 other thread corresponding two each task. At first task sleeps
  for 100 second, <code>Timer</code> should create another thread corresponding to next task and similarly for other task.
  But at debug point , i just see one thread corresponding to <code>Timer</code>. Here also i can see sequential execution of task.  Why not 17 threads?</p>
  
  <p><strong>UPDATE</strong> :- As per <a href="http://docs.oracle.com/javase/6/docs/api/java/util/Timer.html#scheduleAtFixedRate%28java.util.TimerTask,%20long,%20long%29" rel="noreferrer">ScheduleAtFixedRate javadocs</a> , <code>each execution is scheduled relative to the scheduled execution time of the initial execution. If an execution is delayed for any reason (such as garbage collection or other background activity), two or more executions will occur in rapid succession to "catch up. what does that mean?</code> To me it gives impression, if second task is due even first task is not completed, then timer will create new thread for due task. Is n't it?</p>