I am wondering what happens if I schedule a Bean method with @Scheduled at, lets say, every hour开发者_如何学C, but the method execuation takes more than one hour actually.
Will the execution be terminated?
No, there is no mechanism that will terminate your thread. If the thread runs for "too long", that is your problem :-).
Note: You can use the annotation @Scheduled(fixedDelay=xxx)
to only start a new thread when the old thread has finished. That would avoid the problem of multiple threads running in parallel. However, a thread running for too long or even hanging) may of course still cause other problems.
If you are worried that a thread might take too long, you will have to address that in your code. There really is no other way - the framework/runtime has no way of knowing how long is "too long", and even if it had, it has no way of knowing how to properly terminate your thread. It could just kill it, of course, but that is unlikely to be a good solution (cf. the mess about Thread.stop()
).
精彩评论