Reputation: 133
I am using quartz to schedule a daily batch process, and it runs the first days, but it had happened that fires the event for 2 days or so, and then, it stops firing the job.
The java version i'm using is: java version "1.7.0_25" Quartz version (in POM): org.quartz-scheduler quartz 2.2.1
Here is my code:
Main function for the batch:
public static void main(String[] args) {
try {
SimpleDateFormat sd=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
JobDetail job = JobBuilder.newJob(MyJobClass.class).withIdentity("MyJobClass", "group1").build();
Trigger trigger = TriggerBuilder
.newTrigger()
.withIdentity("MyTrigger", "group1")
.withSchedule(
SimpleScheduleBuilder.simpleSchedule()
.withIntervalInHours(24).repeatForever())
.startAt(sd.parse("2015-01-12 07:30:00"))
.build();
Scheduler scheduler = new StdSchedulerFactory().getScheduler();
scheduler.start();
scheduler.scheduleJob(job, trigger);
String strLog="Batch initiated on " + new Date();
System.out.println(strLog);
log.info(strLog);
} catch (Exception e) {
//log error
}
}
And here is my execute method in the job:
public void execute(JobExecutionContext arg0) throws JobExecutionException {
generateBatchProcess();
}
public void generateBatchProcess(){
try{
//do lots of interesting stuff, calling MyBatis Daos, generating excel files and sending an email
}catch (Exception e){
//log error
}
}
Does someone have an idea of why this happens? Is it the garbage collector something to do with this?
Upvotes: 1
Views: 1526
Reputation: 133
I'm ashamed to admit it was only a "BadProgrammerException" because I had a call to a database connection outside the try...catch block that i hadn't seen before, so the problem was that I was not reaching the database and I couldn't figure it out with the log information (the database connection was intermitent). After I found this out, I corrected the database issue and quartz worked ok.
Upvotes: 2