I have a task in which you need to send a notification if the scheduling deadline is approaching and there are 30 days left and also send a notification 5 days before the rest of the deadline. I have searched a lot now and now I cannot find an answer to which element and how to do it. I thought to use Timer event, but if I do it with the help of cron, then how to understand that you need to leave the task and not run the scheme again every time if sending a notification is not relevant
Timer
class is generally outmoded by the scheduled executor service provided by the Executors framework.
Schedule a task that every so often runs to see if stages of deadline are approaching.
if( thirtyDayNoticeNotYetSent ) {
LocalDate then = … retrieve date due … ;
LocalDate today = LocalDate.now( ZoneId.of( "America/Edmonton" ) ) ;
long daysUntil = ChronoUnit.DAYS.between( today , then ) ;
if( daysUntil < 30 ) { send notification … }
}
Similarly, search for jobs that have not yet had their 5-day notice, and calculate elapsed days. If under five, send notification, and record that fact.
Scheduled executor service has been covered many times on Stack Overflow. So,search to learn more.