10

Something i am not clear on. Say i have jobs randomly scheduled throughout the day and each job takes 30 minutes to run. Say i have five of these jobs running and Tomcat gets killed. Do the jobs restart when i start Tomcat with my application, or are the currently running jobs lost because they already fired?

user671731
  • 489
  • 1
  • 8
  • 17

2 Answers2

21

Short answer, by default, currently running Jobs are considered fired and are not recovered

..but you can set requestRecovery property when you build a Job (JobDetail) to tell Quartz to recover that running Jobs in case of crash a.k.a. "hard shutdown".

Quoting the official documentation here on the bottom of the page:

RequestsRecovery - if a job "requests recovery", and it is executing during the time of a 'hard shutdown' of the scheduler (i.e. the process it is running within crashes, or the machine is shut off), then it is re-executed when the scheduler is started again. In this case, the JobExecutionContext.isRecovering() method will return true.

So you can do for example:

import static org.quartz.JobBuilder.*;

...

JobDetail job = newJob(MyJob.class)
           .withIdentity("myJob", "group1")
           .requestRecovery(true) //This is the guy!
           .build();

...
BugOrFeature
  • 327
  • 1
  • 6
  • 13
zerologiko
  • 1,993
  • 1
  • 18
  • 21
0

Tomcat does not care about your job. It is your task to terminate the job correctly in your webapp when it is shut down.

Michael-O
  • 18,123
  • 6
  • 55
  • 121
  • what i am after is does Quartz retry the jobs which were currently executing or does Quartz throw them away, meaning quartz can not cleanly recover from a jvm crash where a user has no means to "terminate the job correctly" – user671731 Oct 02 '13 at 19:25