What is the best way to initialize quartz?

I'm not sure what the best way to initialize Quartz is to schedule cron to work. My environment is Tomcat. I have one task that needs to be run every day.

Should I create a separate servlet to initialize the quartz and the schedule of my work?

I think about creating a servlet and in init () I plan my work 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 it seems to me that I always need to maintain a link to SchedulerFactory for Quartz to work, so is there a better option on the servlet?

+4
source share
1 answer

You can take a look at the Cookbook section of the Quartz website .

There are two simple built-in methods for running Quartz Scheduler in a servlet environment, using either <listener> or <servlet> in a web.xml application.

+3
source

Source: https://habr.com/ru/post/1315813/


All Articles