当tomcat启动但它不工作时,我试图启动一个石英进程,这是我的简单代码:我的ServletContextListener:
包石英。测试;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.apache.log4j.Logger;
import org.quartz.CronScheduleBuilder;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;
public class ApplicationStartup implements ServletContextListener {
private static Logger log = Logger.getLogger(ApplicationStartup.class);
public static final String QUARTZ_FACTORY_KEY = "org.quartz.impl.StdSchedulerFactory.KEY";
private StdSchedulerFactory factory = null;
public void contextDestroyed(ServletContextEvent event) {
try
{
factory.getDefaultScheduler().shutdown();
} catch (SchedulerException ex)
{
log.info("catch");
}
}
public void contextInitialized(ServletContextEvent sce) {
System.out.println("THE APPLICATION STARTED");
ServletContext ctx = sce.getServletContext();
JobDetail job = JobBuilder.newJob(HelloJob.class).withIdentity("dummyJobName", "group1").build();
Trigger trigger = TriggerBuilder.newTrigger().withIdentity("dummyTriggerName", "group1")
.withSchedule(CronScheduleBuilder.cronSchedule("0/5 * * * * ?")).build();
try {
factory = new StdSchedulerFactory();
ctx.setAttribute(QUARTZ_FACTORY_KEY, factory);
Scheduler scheduler= factory.getScheduler();
scheduler.start();
scheduler.scheduleJob(job, trigger);
} catch (SchedulerException e) {
e.printStackTrace();
}
}
} 我的工作:
package quartz.test;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
public class HelloJob implements Job
{
public void execute(JobExecutionContext context) throws JobExecutionException {
System.out.println("Hello Quartz!");
}
}
web.xml
<context-param>
<param-name>quartz:shutdown-on-unload</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>quartz:wait-on-shutdown</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>quartz:start-scheduler-on-load</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>quartz:config-file</param-name>
<param-value>/WEB-INF/classes/quartz.properties</param-value>
</context-param>
<listener>
<listener-class>
org.quartz.ee.servlet.QuartzInitializerListener
</listener-class>
</listener>
编辑: 现在工作开始了,但我收到错误:20/08/2013 11:18:19 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads 严重:Web 应用程序 [/monitor] 似乎已经启动了一个名为 [ QuartzTest_Worker-1] 但未能阻止它。这很可能造成内存泄漏。
将应用程序重新部署到tomcat时在服务器上请帮助
谢谢,