title: Running scheduler in Spring boot is spawning a process external to Spring boot application context
body: <p>I am scheduling a task that runs at fixed rate in Spring boot. The function that I am using to schedule a a task is as below:</p>
  <pre><code>private void scheduleTask(Store store, int frequency) {
          final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
          Runnable task = store::scan;
          scheduler.scheduleAtFixedRate(task, 0, frequency, TimeUnit.MILLISECONDS);
      }
  </code></pre>
  <p>This works fine but if if there is an exception at application startup, the application should exit on exception. What is happening is that I get the exception in the log and the message &quot;Application Failed to start&quot; but looks like the scheduler shows as still running although it looks like only the scheduled thread is still running.</p>
  <p>Any hints on how to properly schedule an asynchronous task in a Spring boot application? I tried the @Scheduled annotation but it does not run at all.</p>