Skip to content

Instantly share code, notes, and snippets.

@mattraykowski
Created February 13, 2015 22:09
Show Gist options
  • Save mattraykowski/94fa8b5f76512fbb299e to your computer and use it in GitHub Desktop.
Save mattraykowski/94fa8b5f76512fbb299e to your computer and use it in GitHub Desktop.
Shutting down a Scheduler on context destruction.
@Configuration
public class SpringConfiguration {
@Bean(destroyMethod="shutdown")
public Scheduler helloJob() {
JobDetail job = new JobDetail();
job.setName("dummyJobName");
job.setJobClass(HelloJob.class);
CronTrigger trigger = new CronTrigger();
trigger.setName("thirtySecondsTrigger");
trigger.setCronExpression("0/30 * * * * ?");
Scheduler scheduler = new StdSchedulerFactory().getScheduler();
scheduler.start();
scheduler.scheduleJob(job, trigger);
return scheduler;
}
}
public class HelloJob implements Job {
public void execute(JobExecutionContext context) throws JobExecutionException {
System.out.println("Hello Quartz!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment