Issue
I'm working on a Springboot app that includes a task that's executed on a schedule. It typically takes about two to three minutes to run.
@Scheduled(cron = "* */30 * * * *")
public void stageOfferUpdates() throws SQLException {
...
}
We have a requirement to be able to kick off the execution of that task at any time by calling a rest endpoint. Is there a way my @GET
method can programmatically kick this off and immediately return an http 200 OK
?
Solution
So you just want to trigger an async task without waiting for results. Because you are using Spring, the @Async
annotation is an easy way to achieve the goal.
@Async
public void asyncTask() {
stageOfferUpdates();
}
Answered By - Pentragon
Answer Checked By - David Marino (JavaFixing Volunteer)