views:

107

answers:

1

I'm not really sure what is the best way to initialize Quartz to schedule a cron job. My environment is just Tomcat. I just have one job that needs to be triggered every day.

Should I create a separate Servlet just to initalize Quartz and schedule my job?

I'm thinking of creating a Servlet and on the init() schedule my job something like this:

SchedulerFactory sf=new StdSchedulerFactory();
Scheduler sched=sf.getScheduler();
JobDetail jd=new JobDetail("job1","group1",CronJob.class);
CronTrigger ct=new CronTrigger("cronTrigger","group2","0 0/1 * * * ?");
sched.scheduleJob(jd,ct);
sched.start();

I'm new to Quartz but I guess I always need to keep a reference to the SchedulerFactory in order for Quartz to be running, therefore having that on a Servlet will be best option?

+1  A: 

You might want to take a look at the Cookbook section on the Quartz site.

There are two easy built-in methods for starting a Quartz Scheduler within a servlet environment, using either a <listener> or <servlet> in the app's web.xml.

matt b
Nice link thanks. I think I'll use listener and in Quartz properties file I'll specify use of XMLSchedulingDataProcessorPlugin to schedule my jobs.
Marquinio