quartz在tomcat下配置使用
写一个要需要执行任务的类DumbJob,实现Job接口
package com.lll;import org.quartz.Job;import org.quartz.JobExecutionContext;import org.quartz.JobExecutionException;public class DumbJob implements Job {public void execute(JobExecutionContext arg0) throws JobExecutionException {System.err.println("DumbJob is executing.");}}
?
建两个配置文件quartz.properties和quartz_job.xml,放在classes下quartz.propertiesorg.quartz.scheduler.instanceName = TestSchedulerorg.quartz.scheduler.instanceId = oneorg.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPoolorg.quartz.threadPool.threadCount = 2org.quartz.threadPool.threadPriority = 4org.quartz.plugin.triggHistory.class = org.quartz.plugins.history.LoggingTriggerHistoryPluginorg.quartz.plugin.triggHistory.triggerFiredMessage = Trigger {1}.{0} fired job {6}.{5} at: {4, date, HH:mm:ss MM/dd/yyyy}org.quartz.plugin.triggHistory.triggerCompleteMessage = Trigger {1}.{0} completed firing job {6}.{5} at {4, date, HH:mm:ss MM/dd/yyyy} with resulting trigger instruction code: {9}org.quartz.plugin.jobInitializer.class = org.quartz.plugins.xml.JobInitializationPluginorg.quartz.plugin.jobInitializer.fileName = quartz_job.xmlorg.quartz.plugin.jobInitializer.overWriteExistingJobs = falseorg.quartz.plugin.jobInitializer.failOnFileNotFound = trueorg.quartz.plugin.shutdownhook.class = org.quartz.plugins.management.ShutdownHookPluginorg.quartz.plugin.shutdownhook.cleanShutdown = true
?
quartz_job.xml<?xml version="1.0" encoding="UTF-8"?><quartz> <job> <job-detail> <name>helloworld</name> <group>group1</group> <job-class>com.lll.DumbJob</job-class> </job-detail> <trigger> <cron> <name>test</name> <group>group1</group> <job-name>helloworld</job-name> <job-group>group1</job-group> <cron-expression>0/1 * * * * ?</cron-expression> </cron> </trigger></job></quartz>
?
?
配置web.xml<?xml version="1.0" encoding="UTF-8"?><web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"><servlet> <servlet-name> QuartzInitializer </servlet-name> <servlet-class> org.quartz.ee.servlet.QuartzInitializerServlet </servlet-class> <init-param> <param-name>config-file</param-name> <param-value>/quartz.properties</param-value> </init-param> <init-param> <param-name>shutdown-on-unload</param-name> <param-value>true</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list></web-app>
?
?
?
quartz.jar见附件,启动tomcat在控制台可看到打印的结果
?
1 楼 eric_dc 2012-02-22 不行啊。不报错,控制台看不到打印结果