| Author |
Message |
![[Post New]](/forums/templates/default/images/icon_minipost_new.gif) 06/10/2012 22:28:21
|
skraana
neo
Joined: 05/16/2012 00:02:41
Messages: 6
Offline
|
Hi.,
I have a job which runs on every monday,tuesday,friday. I'm using cron triggers.
But if i pause the job on sunday and resume the same job on thursday, i could see that the old jobs (monday's and tuesday's jobs) have been triggered at the moment when i resume job on thursday. but the old jobs should have not been triggered , only the upcoming jobs should get triggered.
How can i ignore the old jobs getting run..??
I have tried with the following scenarios.
1) nextFireTime = cronTrigger.getFireTimeAfter(null);
cronTrigger.setNextFireTime(nextFireTime);
2)cronTrigger.setMisfireInstruction(CronTrigger.MISFIRE_INSTRUCTION_DO_NOTHING);
3) cronTrigger.updateAfterMisfire(null);
But nothing works fine for me. :( Please help me in proving a solution on the above problem
Thanks
SK Raana (Thalaivar SuperStar's Fanatic)
|
|
|
 |
![[Post New]](/forums/templates/default/images/icon_minipost_new.gif) 06/11/2012 04:52:14
|
adahanne
master
Joined: 03/20/2012 23:14:46
Messages: 78
Offline
|
Hello ,
The scenario 2, cronTrigger.setMisfireInstruction(CronTrigger.MISFIRE_INSTRUCTION_DO_NOTHING); should have been enough (the documentation states :
Code:
/**
* <p>
* Instructs the <code>{@link Scheduler}</code> that upon a mis-fire
* situation, the <code>{@link CronTrigger}</code> wants to have it's
* next-fire-time updated to the next time in the schedule after the current
* time (taking into account any associated <code>{@link Calendar}</code>,
* but it does not want to be fired now.
* </p>
*/
public static final int MISFIRE_INSTRUCTION_DO_NOTHING = 2;
could you please share more details such as the initialization code/ quartz.properties / logs / quartz version , that can reproduce the problem ?
|
|
|
 |
![[Post New]](/forums/templates/default/images/icon_minipost_new.gif) 06/11/2012 21:38:21
|
skraana
neo
Joined: 05/16/2012 00:02:41
Messages: 6
Offline
|
Hello..,
This is wat my code..,
and i'm using this jar : quartz-all-1.5.2.jar
cronTrigger =
(CronTrigger)scheduler.getTrigger(JOB_NAME, JOB_GROUP_NAME);
Date nextFireTime = cronTrigger.getNextFireTime();
if ((nextFireTime.getTime()) < System.currentTimeMillis()) {
nextFireTime = cronTrigger.getFireTimeAfter(null);
if (nextFireTime == null){ scheduler.deleteJob(JOB_NAME,JOB_GROUP_NAME);
}else{ cronTrigger.setNextFireTime(nextFireTime);
cronTrigger.setMisfireInstruction(CronTrigger.MISFIRE_INSTRUCTION_DO_NOTHING);
cronTrigger.updateAfterMisfire(null);
scheduler.resumeJob(JOB_NAME ,JOB_GROUP_NAME);
}
}
Here i have tried with all possible scenarios., but nothing turned up. :(
My logic is that., if the next fire time of my job is lesser than the current time then im trying to update the next fire time with the new time which is greater than the current date.
if my next fire time is null which means the job has reached the end time, then im deleting that job. so that the status will be completed.
but even though im updating the next fire time with the new date.., it runs all the paused old jobs., it should have not been run. pls help me on this problem..,
Thanks
SK Raana
|
|
|
 |
![[Post New]](/forums/templates/default/images/icon_minipost_new.gif) 06/12/2012 05:27:45
|
adahanne
master
Joined: 03/20/2012 23:14:46
Messages: 78
Offline
|
Hello,
I was rather mentioning the code that creates/ initializes your cronTrigger (the code you sent just shows that you are trying to handle manually misfires; I'm pretty sure you don't need to do that)
could you attach a simple test case, to reproduce your misfire behaviour ? You could attach your java code + your quartz.properties.
Thanks
|
|
|
 |
![[Post New]](/forums/templates/default/images/icon_minipost_new.gif) 06/12/2012 05:35:08
|
skraana
neo
Joined: 05/16/2012 00:02:41
Messages: 6
Offline
|
Hello..,
public class MyCronTrigger extends CronTrigger {
/**
*
*/
private static final long serialVersionUID = 1L;
public MyCronTrigger(String jobName,String gruopName,String cronExpression) throws ParseException{
super(jobName,gruopName,cronExpression);
}
@Override
public Date getNextFireTime() {
Date nextFireTime = super.getNextFireTime();
if (nextFireTime.getTime() < System.currentTimeMillis()) {
nextFireTime = super.getFireTimeAfter(null);
super.setNextFireTime(nextFireTime);
}
return nextFireTime;
}
}
SchedulerFactory schedulerFactory = new StdSchedulerFactory();
Scheduler scheduler = schedulerFactory.getScheduler();
JobDetail jobDetail = new JobDetail(JOB_NAME,JOB_GROUP_NAME, MyJob.class);
CronTrigger cronTrigger = new MyCronTrigger(JOB_NAME ,JOB_GROUP_NAME, cronExpression);
cronTrigger.setStartTime(startDate);
cronTrigger.setEndTime(endDate);
scheduler.scheduleJob(jobDetail, cronTrigger);
scheduler.start();
This is how im creating my job.
For pausing my job i have used the below logic
cronTrigger =
(CronTrigger)scheduler.getTrigger(JOB_NAME, JOB_GROUP_NAME);
Date nextFireTime = cronTrigger.getNextFireTime();
if ((nextFireTime.getTime()) < System.currentTimeMillis()) {
nextFireTime = cronTrigger.getFireTimeAfter(null);
if (nextFireTime == null){ scheduler.deleteJob(JOB_NAME,JOB_GROUP_NAME);
}else{ cronTrigger.setNextFireTime(nextFireTime);
cronTrigger.setMisfireInstruction(CronTrigger.MISFIRE_INSTRUCTION_DO_NOTHING);
cronTrigger.updateAfterMisfire(null);
scheduler.resumeJob(JOB_NAME ,JOB_GROUP_NAME);
}
}
pls help me to give a solution for this problem
Thanks
SK Raana
|
|
|
 |
![[Post New]](/forums/templates/default/images/icon_minipost_new.gif) 06/12/2012 07:11:50
|
adahanne
master
Joined: 03/20/2012 23:14:46
Messages: 78
Offline
|
why didnt you use :
CronTrigger trigger = newTrigger().withIdentity("trigger1", "group1") .withSchedule(cronSchedule(cronExpression).withMisfireHandlingInstructionDoNothing()).build();
to create your trigger in the first place ? You would not need all the code you wrote after.
btw, when you do your update operations on the trigger, you are working with a clone of the trigger; so you would need to re schedule your trigger after updates
|
|
|
 |
![[Post New]](/forums/templates/default/images/icon_minipost_new.gif) 06/12/2012 22:57:14
|
skraana
neo
Joined: 05/16/2012 00:02:41
Messages: 6
Offline
|
Hello adahanne..
cronTrigger = newTrigger().withIdentity(CannedReportingMailJob.JOB_NAME , ScheduleReportJobConstants.JOB_GROUP_NAME) .withSchedule(cronSchedule(cronExpression).withMisfireHandlingInstructionDoNothing()).build();
THis line contains the compile error "The method newTrigger() is undefined for the type MyClass". i tried to import the following package
import static org.quartz.JobBuilder.*;
but i could not resolve the compilation issues.., thar import line itself contains the compilation error as "The import org.quartz.JobBuilder cannot be resolved"
I'm using this jar : quartz-all-1.5.2.jar
I'm new to this quartz., pls assist me in this.
Thanks
SK Raana
|
|
|
 |
![[Post New]](/forums/templates/default/images/icon_minipost_new.gif) 06/13/2012 07:06:33
|
adahanne
master
Joined: 03/20/2012 23:14:46
Messages: 78
Offline
|
right, I provided an example with the quartz builder API, that actually appeared in quartz 2.0 : http://quartz-scheduler.org/documentation/quartz-2.x/new-in-quartz-2
whether you can switch to a more modern version or quartz, or you can use the old style : http://quartz-scheduler.org/documentation/quartz-1.x/examples/Example5
|
|
|
 |
|
|