Surprisingly, there is still no quartz method for obtaining the previous response time based on the expression CronExpression ...
How to find out the time of the last dismissal?
If you control a basic CRON, for example, 0 0 0 * * ? (at 00:00:00 in the morning every day), you can use the solution of Joao Neves (using com.cronutils.model.time.ExecutionTime).
Edit : I did other tests, and it seems to work better with the latest version (previous tests were done with 3.1.6). Note. You need Java 8 if you want to use the & lt; 3.1.6.
Otherwise, if you are managing a complex CRON, for example, 0 30 11 ? * MON,THU * 0 30 11 ? * MON,THU * , it will not work. You will get random results (I had an environment for this ...).
The solution you can use is to save it when you start your work.
How to verify that a task has been started?
The solution I found is to use getNextValidTimeAfter from Quartz (CronExpression). This one works great. You ask me what I'm talking about as we look for the previous valid time! You are right, give me one second!
Let's imagine that we have CRON once a month (0 0 16 1 *? = At 16:00:00, on the 1st of every month), and we want to check every day whether the previous execution worked. You will need to store getNextValidTime at each execution and compare this date with today's date. for example (DD / MM / YYYY format):
• 01/01/2019 → the task worked, we store the next fire (let it be called nextFireTime ):
CronExpression trigger = new CronExpression("0 0 16 1 * ?"); Date nextFireTime = trigger.getNextValidTimeAfter(new Date());
• 02/01/2019 → day check: 02/01/2019 & lt; 02/01/2019 OK
...
• 01/02/2019 → imagine that the server is not working, the task is not running.
• 02.02.2009 → the server is turned on, check of the day: 02.02.2009> 01.02.2009 KO!
→ We know that the previous fire did not work. You can know what to do, what you want (to start work and save a new nextFireTime).
Another option that might interest you is see MISFIRE_INSTRUCTION_FIRE_NOW .
The task runs immediately after the planner detects a misfire situation. This is a smart policy. Example scenario: you have planned to clean the system at 2 a.m. Unfortunately, the application was closed due to maintenance by that time and returned at 3 a.m. So the trigger worked, and the scheduler tries to save the situation, run it as soon as possible - at 3 a.m.
C ( https://dzone.com/articles/quartz-scheduler-misfire )
eg.:
Trigger trigger = newTrigger(). withSchedule( cronSchedule("0 0 9-17 ? * MON-FRI"). withMisfireHandlingInstructionFireAndProceed() ). build();
White Paper: https://www.quartz-scheduler.org/api/2.1.7/org/quartz/CronTrigger.html