title: Shutdown scheduler - Java
body: <p>I have the following class, which schedules the "update" method to be executed every 5 minutes. The thing is I want "update" to be executed a fixed number of times. When I use <strong>scheduler.shutdown()</strong> the update method does not execute anymore, but the program is still running, I suppose doing nothing.</p>
  
  <p>How can I stop it completely?</p>
  
  <pre><code>static Runnable update = new Runnable() {        
      @Override
      public void run() {
  
          if (count &gt;= MAX_UPDATES) {
              scheduler.shutdown();
          } else {
              //Do something
              count++;
          }
      }
  }
  
  public static void main(String[] args) {
  
      ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
      scheduler.scheduleAtFixedRate(update, 0, 5, TimeUnit.MINUTES);
  }
  </code></pre>