title: What is the correct way to restart a ScheduledExecutorService scheduled task?
body: <p>I have a scheduled task (running in fixed delay execution), started like this:</p>
  
  <pre><code>executoreService.scheduleWithFixedDelay(repeatingThread, 0, numOfSeconds, TimeUnit.SECONDS);
  </code></pre>
  
  <p>On every start of cycle, I check for a change in a settings file, and then I want to restart the task. The settings file also contains length of the interval (<code>numOfSeconds</code> in the above code).</p>
  
  <p>Currently, I am using the following code to restart the task:</p>
  
  <pre><code>executoreService.shutdownNow();
  try {
   while(!executoreService.awaitTermination(5, TimeUnit.SECONDS)){
    logger.debug("awaiting termintation");
   }
  } catch (InterruptedException e) {
   logger.debug("interrupted, continuing", e);
  }
  // initialize startup parameters
  init();
  // start the main scheduled timer
  executoreService.scheduleWithFixedDelay(repeatingThread, 0, numOfSeconds, TimeUnit.SECONDS);
  </code></pre>
  
  <p>I'm not sure about these API calls. What is the recommended way to restart the task (possibly with a new delay)?</p>