Skip to content
Discussion options

You must be logged in to vote

What happens if an exception is thrown in a @scheduled method? Is the task stopped and all future invocations stopped too?

Nope, it is not stopped.

We log a message with level ERROR and the text that starts with Error occurred while executing task for trigger....

Furthermore, we fire the FailedExecution CDI event, both synchronously and asynchronously. You can observe these events and inspect the cause:

import jakarta.enterprise.event.Observes;
import jakarta.enterprise.context.ApplicationScoped;

@ApplicationScoped
class MyBean {

   void onFailureSync(@Observes FailedExecution failure) {
      // do something with failure.getException()
   }
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@mkouba
Comment options

mkouba Jul 10, 2023
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
1 participant