title: How can I execute a method every x second for y time in java
body: <p>I want to execute a method every second for 20 times. </p>
  
  <p>Actually I have timer</p>
  
  <pre><code>Timer timer = new Timer();
  int begin = 0;
  int timeInterval = 1000;
  
  timer.scheduleAtFixedRate(new TimerTask() {
      @Override
      public void run() {
          //call the method
      }
  }, begin, timeInterval);
  </code></pre>
  
  <p>How can I call a method 20 times with this interval?</p>