Spicy Spring : Scheduler does not shutdown

On my current project we use Java 8, Spring 4.3 and Tomcat 7.0 as application server. After the scheduling functionality was added to the project the application server did not shut down any more, it hung till the end of time.

I like to use the default Java implementations when possible so the configured scheduler was the java.util.concurrent.ScheduledThreadPoolExecutor.

After some investigation we found out that the application server did not shutdown because the created ScheduledExecutorService bean did not stop. The threads in the thread pool didn’t stop when the application context is destroyed. The destroyMethod is defined and Spring calls the shutdown method but it still did not stop the application server. When I tested with Spring Boot it shuts down without a problem.

Spring has also their own ThreadPoolTaskScheduler with much more configuration options. Strangely it does not implement the same interface java.util.concurrent.ScheduledExecutorService as I would expect from the Spring framework but you can use both implementations.

With the Spring ThreadPoolTaskScheduler the application server does shutdown.

Leave a Reply

Your email address will not be published. Required fields are marked *