第一篇中增加的是程序代码的实现,本篇我们将通过配置文件进行定时器的配置,减少代码量,提高灵活性。
1、需要用到的文件:quartz.properties,据说这个文件如果没有的话,按默认的走,结果布署到tomcat中,提示找不到该文件;
#============================================================================ # Configure Main Scheduler Properties #============================================================================ org.quartz.scheduler.instanceName = QuartzScheduler org.quartz.scheduler.instanceId = AUTO #============================================================================ # Configure ThreadPool #============================================================================ org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool org.quartz.threadPool.threadCount =2 org.quartz.threadPool.threadPriority = 5 #============================================================================ # Configure JobStore #============================================================================ org.quartz.jobStore.misfireThreshold = 60000 org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore #============================================================================ # Configure Plugins #============================================================================ org.quartz.plugin.triggHistory.class = org.quartz.plugins.history.LoggingJobHistoryPlugin org.quartz.plugin.jobInitializer.class = org.quartz.plugins.xml.JobInitializationPlugin org.quartz.plugin.jobInitializer.fileNames = jobs.xml org.quartz.plugin.jobInitializer.overWriteExistingJobs = true org.quartz.plugin.jobInitializer.failOnFileNotFound = true org.quartz.plugin.jobInitializer.scanInterval = 10 org.quartz.plugin.jobInitializer.wrapInUserTransaction = false
2、jobs.xml ,上文提到的配置文件,配置触发器和job名称等;
<?xml version=‘1.0‘ encoding=‘utf-8‘?> <quartz xmlns="http://www.opensymphony.com/quartz/JobSchedulingData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opensymphony.com/quartz/JobSchedulingData http://www.opensymphony.com/quartz/xml/job_scheduling_data_1_5.xsd" version="1.5"> <job> <job-detail> <name>HelloWorld</name> <group>DEFAULT</group> <description> A job that just for test </description> <job-class> cn.jfinal.job.RedPacketValidate </job-class> <volatility>false</volatility> <durability>false</durability> <recover>false</recover> </job-detail> <trigger> <simple> <name>HelloTrigger1</name> <group>DEFAULT</group> <job-name>RedPacketValidate</job-name> <job-group>DEFAULT</job-group> <start-time>2015-10-26T16:56:30</start-time> <!-- repeat indefinitely every 10 seconds --> <repeat-count>-1</repeat-count> <repeat-interval>10000</repeat-interval> </simple> </trigger> </job> </quartz>
上面这两个文件要放在apache-tomcat-7.0.59\webapps\jfinal_demo\WEB-INF\classes 中,才能有效。
3、一些必须的jar包要添加到lib中:
创建一个Web项目,将quartz-1.6.0.jar,以及lib目录下面core下所有jar,optional目录下的所有commons-beanutils.jar和commons-digester-1.7.jar,build目录下的jta.jar都放入Web项目的WEB-INF"lib目录下。
jta.jar说明:java JTA规范;
4、web.xml 配置
<servlet> <servlet-name>QuartzInitializer</servlet-name> <display-name>Quartz Initializer Servlet</display-name> <servlet-class> org.quartz.ee.servlet.QuartzInitializerServlet </servlet-class> <load-on-startup>1</load-on-startup> <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> </servlet>
总体参考:http://www.cnblogs.com/phinecos/archive/2008/09/03/1283103.html
时间: 2024-11-05 14:57:12