Lifecycle (starting, shutting down) of a ScheduledExecutorService inside a Spring Signleton

333 Views Asked by At

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>#onApplicationEventmethod - 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

0

There are 0 best solutions below