什么是初始化Quartz的最佳方法?

时间:2021-07-26 02:13:48

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.

我不确定什么是初始化Quartz来安排cron作业的最佳方法。我的环境是Tomcat。我有一份工作需要每天触发。

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

我应该创建一个单独的Servlet来初始化Quartz并安排我的工作吗?

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

我正在考虑创建一个Servlet,并在init()上安排我的工作:

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?

我是Quartz的新手,但我想我总是需要保留对SchedulerFactory的引用才能运行Quartz,因此在Servlet上使用它是最佳选择吗?

1 个解决方案

#1


3  

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

您可能需要查看Quartz站点上的Cookbook部分。

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.

有两种简单的内置方法可以在servlet环境中启动Quartz Scheduler,在app的web.xml中使用

#1


3  

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

您可能需要查看Quartz站点上的Cookbook部分。

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.

有两种简单的内置方法可以在servlet环境中启动Quartz Scheduler,在app的web.xml中使用