Last Updated: February 25, 2016
·
2.654K
· jorgeu

Quartz previus fire time

When your job is executed the JobExecutionContext you receive can give you the date of the previus job run. That's great if you're processing only modified objects from your data model.
The method is ctx.getPreviousFireTime() and to make it work between restarts (a problem I had) the trigger must be kept un touched.
Keep an unique name/group for your trigger and then see if the configured cron expression is the same as the running one.</p>
Java trigger = (CronTrigger) scheduler.getTrigger(name, group); if(!trigger.getCronExpression().equals(configuredCron)) { // ok then reschedule it. the config has changed }

So you can keep getting the previusFireTime between restart unless the configuration changes. After we do a schedule or reschedule of the trigger we will not get previusFireTime at the first run. If for some reason the application is beign restarted often then it will make a difference.</p>