title: Is it safe to shut down ScheduledExecutorService?
body: <p>I am implementing a service that does some longer running tasks that is emulated by <code>Thread.sleep(10000)</code> here. When I ctrl+c the execution I never get the <code>InterruptedException</code> that I would expect. I am wondering why.</p>
  
  <pre><code>package simple;
  
  import my.util.Now;
  import io.dropwizard.lifecycle.Managed;
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  
  import java.util.concurrent.Executors;
  import java.util.concurrent.ScheduledExecutorService;
  import java.util.concurrent.TimeUnit;
  
  public class EmailSender implements Managed {
  
      private static final Logger LOGGER = LoggerFactory.getLogger(EmailSender.class);
      ScheduledExecutorService executorService = Executors.newScheduledThreadPool(3);
  
      // Constructor
      public EmailSender() {}
  
      @Override
      public void start() {
          LOGGER.info("Starting email sender thread: {}", Thread.currentThread().getName());
          Runnable task = () -&gt; {
              LOGGER.info("Running: {} in thread: {}", Now.now(), Thread.currentThread().getName());
              try {
                  Thread.sleep(10000);
              } catch (InterruptedException ie) {
                  LOGGER.error("Task is being interrupted: {}", ie.getMessage());
              }
          };
          executorService.scheduleAtFixedRate(task, 0, 5, TimeUnit.SECONDS);
      }
  
      @Override
      public void stop() {
          LOGGER.info("Stopping email sender thread: {}", Thread.currentThread().getName());
          executorService.shutdown();
  
      }
  }
  </code></pre>
  
  <p>Is this safe to assume that <code>executorService.shutdown();</code> waits till the execution is over for the task this way?</p>