准备工作:
1.导入quartz-1.x.x.x.jar到lib,可能还需要lib/sh4j-api-1.x.x.jar,log4g,sh4j.api,1,x,x,jar,sh4j.nop,1,x,x,jar
2.在src目录下创建quartz.properties(压缩quartz-1.x.x.x.jar 下的org/quarz下可得)
[
html]
# 配置主调度器属性
org.quartz.scheduler.instanceName = DefaultQuartzScheduler
org.quartz.scheduler.rmi.export = false
org.quartz.scheduler.rmi.proxy = false www.2cto.com
org.quartz.scheduler.wrapJobExecutionInUserTransaction = false
# 配置线程池
# Quartz线程池的实现类
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
# 线程池的线程数量
org.quartz.threadPool.threadCount = 10
# 线程池里线程的优先级
org.quartz.threadPool.threadPriority = 5
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true
# 配置作业存储
org.quartz.jobStore.misfireThreshold = 60000
org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
#org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.HSQLDBDelegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate
#org.quartz.jobStore.useProperties = true
#org.quartz.jobStore.tablePrefix = QRTZ_
#org.quartz.jobStore.isClustered = false
#org.quartz.jobStore.maxMisfiresToHandleAtATime=1
3.编写触发时要执行的类
[java]
package com.quartz;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.Trigger;
import org.springframework.scheduling.quartz.QuartzJobBean;
public class TestQuartzJob extends QuartzJobBean{
@Override
protected void executeInternal(JobExecutionContext jobexecutioncontext) throws JobExecutionException {
// TODO Auto-generated method stub
Trigger trigger = jobexecutioncontext.getTrigger();
String triggerName = trigger.getName();
System.out.println("MyQuartzJobBean"+triggerName);
}
}
4.配置sping管理的配置文件quartzContext.xml
[html]
< xml version="1.0" encoding="UTF-8" >
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/jee