问题:我想在WEB容器启动时就执行任务怎么办呢
Quartz:使用QuartzInitializerListener就可办到了
请注意它的优先级别比QuartzInitializerServlet要高
在web.xml中可配置的参数如下:
如:
- <context-param>
- <param-name>quartz:config-file</param-name>
- <param-value>/quartz.properties</param-value>
- </context-param>
以下二者参数可代表都是同一个意思
quartz:config-file 或者 config-file
quartz:shutdown-on-unload 或者 shutdown-on-unload
quartz:wait-on-shutdown
quartz:start-on-load 或者 start-scheduler-on-load
quartz:start-delay-seconds 或者 start-delay-seconds
quartz:servlet-context-factory-key 或者 servlet-context-factory-key
默认值为:org.quartz.impl.StdSchedulerFactory.KEY
quartz:scheduler-context-servlet-context-key 或者 scheduler-context-servlet-context-key
以上参数都是根据QuartzInitializerListener源码得来的
QuartzInitializerListener源码如下:
- package org.quartz.ee.servlet;
- import javax.servlet.ServletContext;
- import javax.servlet.ServletContextEvent;
- import javax.servlet.ServletContextListener;
- import org.quartz.Scheduler;
- import org.quartz.impl.StdSchedulerFactory;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- public class QuartzInitializerListener implements ServletContextListener {
- public static final String QUARTZ_FACTORY_KEY = "org.quartz.impl.StdSchedulerFactory.KEY";
- private boolean performShutdown;
- private boolean waitOnShutdown;