title: Future.cancel() is not cancelling the scheduled execution of ScheduledExecutorService
body: <p>I am scheduling a task as:</p>
  
  <pre><code>ScheduledExecutorService dataService = Executors.newScheduledThreadPool(1);
  Future&lt;?&gt; dataTimerHandle = dataService.scheduleAtFixedRate(runnable, 100, freq, TimeUnit.MILLISECONDS);
  </code></pre>
  
  <p>This works fine without a flaw.</p>
  
  <p>However, when a certain flag becomes <code>true</code> on user action, the task is no more required periodically, and needs to be executed just once. I then attempt cancelling the task and submitting it just once as follows:</p>
  
  <pre><code>if(!dynamicUpdate) {
      dataTimerHandle.cancel(true); 
      dataTimerHandle = dataService.submit(runnable);
  }
  else { //Reschedule again:
      dataTimerHandle = dataService.scheduleAtFixedRate(runnable, 100, freq, TimeUnit.MILLISECONDS);
  }
  </code></pre>
  
  <p>But seems like the runnable is still executing periodically and <code>cancel()</code> is not working as expected.
  Is there an alternate strategy for this?</p>