How can I declare a timer which is invoked every x days? For example, I want to invoke the timer every 40 days. How should I setup my timer? I cannot convert “40 days” to hours as hours expects a range between 0-23. I cannot put 40 days in dayOfMonth as it expects a range between 1 to 31. So how should I do that?
ScheduleExpression expression = new ScheduleExpression();
expression.second("0").minute("0").hour("0").dayOfMonth("40");
You can try the below method of
TimerServiceinterface to create a interval timer, that will expire every 40 days by specifying that duration asintervalDurationafter initialization of it byinitialDurationin milliseconds.createTimer(long initialDuration, long intervalDuration, java.io.Serializable info)Create an interval timer whose first expiration occurs after a specified duration, and whose subsequent expirations occur after a specified interval.