title: Lifecycle (starting, shutting down) of a ScheduledExecutorService inside a Spring Signleton
body: <p>I'm using a <code>ScheduledExecutorService</code> inside a Spring Singleton. It executes a periodical check that's scheduled to run every x minutes. I'm lazily (or half-lazily) initializing the Singleton member variables (the Executor) by implementing a <code>ApplicationListener&lt;ContextStartedEvent&gt;#onApplicationEvent</code>method - that created the <code>ScheduledExecutorService</code> and assigns a task.</p>
  
  <p>I need to deal with the shutdown of the <code>ExecutorService</code>, and wonder how to do that properly. I do know that Spring has it's context shutdown process, and wonder whether it's reasonable to call the shutdown somewhere from there.</p>
  
  <p>What exactly happens if the <code>ExecutorService</code> doesn't get shutdown, and the Server is being closed or terminated? Doesn't the JVM just clears all memory related to this program?</p>
  
  <p>Thanks</p>