What's the best way to initialize Quartz?

こ雲淡風輕ζ 提交于 2019-12-10 15:52:58

问题


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

Should I create a separate Servlet to initialize 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:


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.



来源:https://stackoverflow.com/questions/3257074/whats-the-best-way-to-initialize-quartz

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!