Index

Quartz

Hello World

public class HelloJob implements Job {

	@Override
	public void execute(JobExecutionContext context) throws JobExecutionException {
		Object value = context.getJobDetail().getJobDataMap().get("mykey");
		System.out.println("Hello Quartz! " + value);
	}

	public static void main(String[] args) throws Exception {
		CronTriggerImpl trigger = new CronTriggerImpl();
		trigger.setName("dummyTriggerName");
		trigger.setCronExpression("0/5 * * * * ?");

		JobDetailImpl detail = new JobDetailImpl();
		Hashtable<String, String> map = new Hashtable<String, String>();
		map.put("mykey", "myvalue");
		detail.setJobDataMap(new JobDataMap(map));
		detail.setName("dummyJobName");
		detail.setJobClass(HelloJob.class);

		Scheduler scheduler = new StdSchedulerFactory().getScheduler();
		scheduler.start();
		scheduler.scheduleJob(detail, trigger);
	}
}