Skip to content

Tomcat does not shutdown correctly when using @Scheduled [SPR-7231] #11890

@spring-projects-issues

Description

@spring-projects-issues

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:

Issue Links:

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions