[spr-7231] tomcat does not shutdown correctly when using @scheduled created: 24/may/10 updated: 15/jan/19 resolved: 25/may/10 status: cl
[SPR-7231] Tomcat does not shutdown correctly when using @Scheduled
Created: 24/May/10 Updated: 15/Jan/19 Resolved: 25/May/10
Status:
Closed
Project:
Spring Framework
Component/s:
Core
Affects Version/s:
3.0.2
Fix Version/s:
3.0.3
Type:
Bug
Priority:
Major
Reporter:
Jens Göring
Assignee:
Juergen Hoeller
Resolution:
Complete
Votes:
0
Labels:
None
Remaining Estimate:
Not Specified
Time Spent:
Not Specified
Original Estimate:
Not Specified
Attachments:
Text File stacktrace.txt Zip Archive test.zip
Issue Links:
Related
is related to
SPR-6901
Tomcat does not shutdown correctly wh...
Closed
Days since last comment:
2 years, 37 weeks, 4 days ago
Last commented by a User:
true
Last updater:
Spring Issues
Description
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 SPR-6901, 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 SPR-6901)
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
Comments
Comment by Juergen Hoeller [ 25/May/10 ]
Good catch! I've revised ScheduledTaskRegistrar to call shutdownNow()
on any default executor that it happens to use. Since
ConcurrentTaskScheduler is supposed to be simple adapter for an
existing Executor with an external lifecycle, we're not calling
shutdownNow() there but rather in ScheduledTaskRegistrar itself -
specifically for a default executor.
This will be available in tonight's 3.0.3 snapshot. As a workaround
for the time being, specifying an externally configured scheduler bean
should avoid this problem: The lifecycle is then up to that external
bean in any case.
Juergen
Comment by Jens Göring [ 25/May/10 ]
Thanks for the quick reaction and workaround suggestion!
–
Jens Göring
Comment by Jens Göring [ 22/Jun/10 ]
I can confirm that 3.0.3 solves my original problem, thx for the fix!
–
Jens Göring
Comment by Spring Issues [ 14/Jan/19 ]
The Spring Framework has migrated to GitHub Issues. This issue
corresponds to spring-projects/spring-framework#11890.
Generated at Fri Oct 01 21:49:36 UTC 2021 using Jira
8.5.11#805011-sha1:102a195bf8687d9dd541cc7f5503132d0561ea57.