Reputation: 190
Does anyone has any experience with task scheduling in Spring? I understand you can schedule for a fixed time period or interval using annotations https://spring.io/guides/gs/scheduling-tasks/ But I was wondering if anyone knows how to do this using dynamic user input at runtime. For example a user schedules an email to be sent at 5:02pm exactly, is there a way add a new task dynamically using that as a time?
Upvotes: 3
Views: 2333
Reputation: 8495
2.Annotate mail sending method with @Scheduled as below, this method will be called automatically( by spring) for every 5 seconds (5000 ms).
3.Get current time and compare it with NEXT_SEND_TIME.
4.If current time is greater than NEXT_SEND_TIME , then trigger email for that user.
@Scheduled(fixedDelay=5000)
public void sendMail() {
// do step 3 & 4 here
}
Upvotes: 2