-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
Jens Göring opened SPR-7231 and commented
When using @Scheduled
, Tomcat will freeze on shutdown when using Linux. The problem seems to be that ConcurrentTaskScheduler creates an ScheduledExecutorService that uses non-daemon threads which prevent Tomcat to shutdown. This bug is similar to #11566, but not the same, because I already have the fixed version and the code from the fix is never executed in my application.
I guess the difference is that I use @Scheduled
. I attached an code example which is pretty much the same as in http://blog.springsource.com/2010/01/05/task-scheduling-simplifications-in-spring-3-0/
When this application is deployed to Tomcat, and Tomcat is than stopped, Tomcat freezes. I attached a stacktrace where the non-daemon timer thread can be identified.
A solution might be to add this to ScheduledTaskRegistrar.destroy():
if (this.taskScheduler instanceof DisposableBean) {
((DisposableBean)this.taskScheduler).destroy();
}
(which is similar to the fix of #11566)
And make ConcurrentTaskScheduler implement DisposableBean:
public void destroy() throws Exception {
this.scheduledExecutor.shutdown();
}
These changes fix the problem for me.
Please let me know if you see another workaround but to not using @Scheduled
or patching Spring.
Jens Göring
Affects: 3.0.2
Attachments:
- stacktrace.txt (9.45 kB)
- test.zip (3.68 kB)
Issue Links:
- Tomcat does not shutdown correctly when using task:scheduled-taks [SPR-6901] #11566 Tomcat does not shutdown correctly when using task:scheduled-taks