I'm using a ScheduledExecutorService
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 ApplicationListener<ContextStartedEvent>#onApplicationEvent
method - that created the ScheduledExecutorService
and assigns a task.
I need to deal with the shutdown of the ExecutorService
, 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.
What exactly happens if the ExecutorService
doesn't get shutdown, and the Server is being closed or terminated? Doesn't the JVM just clears all memory related to this program?
Thanks