i opened this bug in the spring bug tracker. would be cool if some clever people here can already help me
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Set "true" on daemon property for the scheduler - eg
This is the solution using Java config
or if you want to really get into the details, the config class can be like this
One thing is not supported though is to be able to use multiple TaskSchedulers within a single application. I opened a JIRA for that
Have you tried having your
@Scheduled
bean implementDisposableBean
(so it can be informed when the Spring context is shutting down) and explicitly closing the context in yourmain()
method?Conceptually, I don't see how the code posted can work like you expect. Spring needs to launch new threads to run your
@Scheduled
task at the time/rate you configure, which means that when the code in yourmain()
method exits, there are non-daemon threads still running in the JVM. If you don't tell Spring to shut these threads down, then how will they be terminated?edit: to be clear, I think the solution is to explicitly call
close()
on yourApplicationContext
. Otherwise Spring does not have a way to tell the executor service running your scheduled tasks to shut itself down. A JVM shutdown hook will not be invoked whenmain()
exits since non-daemon threads are still running.