欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Quartz配置  

程序员文章站 2024-03-04 18:42:06
...

  1.添加quartz_jobs_common.xml


<?xml version='1.0' encoding='utf-8'?> <quartz> <job> <job-detail>    <name>TestJob</name>    <group>DEFAULT</group>    <description>TestJob</description>    <job-class>job.TestJob</job-class>    <job-data-map allows-transient-data="true">    <entry>    <key>name</key>    <value>TestJob</value>    </entry> </job-data-map>    </job-detail>    <trigger> <cron> <name>TestJob</name> <group>DEFAULT</group> <job-name>TestJob</job-name> <job-group>DEFALUT</job-group> <cron-expression>0 0/1 * * * ?</cron-expression> </cron> </trigger> </job> </quartz>

2. 添加 quartz.properties

#============================================================================
# Configure Main Scheduler Properties
#============================================================================
org.quartz.scheduler.instanceName = org.quartz.scheduler.instanceId = AUTO
#============================================================================
# Configure ThreadPool
#============================================================================
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 3
org.quartz.threadPool.threadPriority = 5
#============================================================================
# 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 = quartz_jobs_common.xml
org.quartz.plugin.jobInitializer.overWriteExistingJobs = true
org.quartz.plugin.jobInitializer.failOnFileNotFound = true
org.quartz.plugin.jobInitializer.scanInterval = 10

3.在web.xml中添加

<context-param>
<param-name>config-file</param-name>
<param-value>/quartz.properties</param-value>
</context-param>
<context-param>
<param-name>shutdown-on-unload</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>start-scheduler-on-load</param-name>
<param-value>true</param-value>
</context-param>

<listener>
<listener-class>
org.quartz.ee.servlet.QuartzInitializerListener
</listener-class>
</listener>

4.添加quartz.jar包引用 

5.添加执行代码需要继承job类的java类

 

package job;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

public class TestJob implements Job {
	public void execute(JobExecutionContext arg0) throws JobExecutionException {

		System.out.println(1);
	}
}