I am wondering what happens if I schedule a Bean method with @Scheduled at, lets say, every hour, but the method execuation takes more than one hour actually.
Will the execution be terminated?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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()).