Skip to content

Instantly share code, notes, and snippets.

@sharrissf
Created November 30, 2010 00:27
Show Gist options
  • Save sharrissf/720905 to your computer and use it in GitHub Desktop.
Save sharrissf/720905 to your computer and use it in GitHub Desktop.
Quartz Scheduler Example 2 comparison
//Quartz scheduler Example 2 from 1.8.3
// job3 will run 11 times (run once and repeat 10 more times)
// job3 will repeat every 10 seconds (10000 ms)
job = new JobDetail("job3", "group1", SimpleJob.class);
trigger = new SimpleTrigger("trigger3", "group1", "job3", "group1",
new Date(ts), null, 10, 10000L);
ft = sched.scheduleJob(job, trigger);
// the same job (job3) will be scheduled by a another trigger
// this time will only run every 70 seocnds (70000 ms)
trigger = new SimpleTrigger("trigger3", "group2", "job3", "group1",
new Date(ts), null, 2, 70000L);
ft = sched.scheduleJob(job, trigger);
//Quartz scheduler Example 2 from 2.0
// job3 will run 11 times (run once and repeat 10 more times)
// job3 will repeat every 10 seconds
job = newJob(SimpleJob.class)
.withIdentity("job3", "group1")
.build();
trigger = newTrigger()
.withIdentity("trigger3", "group1")
.startAt(startTime)
.withSchedule(simpleSchedule()
.withIntervalInSeconds(10)
.withRepeatCount(10))
.build();
ft = sched.scheduleJob(job, trigger);
// the same job (job3) will be scheduled by a another trigger
// this time will only repeat twice at a 70 second interval
trigger = newTrigger()
.withIdentity("trigger3", "group2")
.startAt(startTime)
.withSchedule(simpleSchedule()
.withIntervalInSeconds(10)
.withRepeatCount(2))
.forJob(job)
.build();
ft = sched.scheduleJob(trigger);
@sharrissf
Copy link
Author

This comparison highlights the problem of figuring out what the parameters are to a constructor vs. reading a Fluent interface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment