初始化 Quartz 的最佳方法是什么?
我不太确定初始化 Quartz 来安排 cron 作业的最佳方法是什么。 我的环境是Tomcat。我有一项工作每天都需要触发。
我应该创建一个单独的 Servlet 来初始化 Quartz 并安排我的工作吗?
我正在考虑创建一个 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();
我是 Quartz 的新手,但我想我总是需要保留对 SchedulerFactory 的引用,以便Quartz 正在运行,因此将其放在 Servlet 上将是最佳选择?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能想看看 Quartz 网站上的 Cookbook 部分。
有两种简单的内置方法用于启动 Quartz Servlet 环境中的调度程序,使用应用程序的 web.xml 中的
或
。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.