1.引入除spring.jar外的Quartz的jar包quartz-all-1.8.6.jar
2.任务类 QuartzJob
01 | public class QuartzJob { |
05 | System.out.println( "Quartz的任务调度!!!work1启用……" ); |
10 | System.out.println( "Quartz的任务调度!!!work2启用……" ); |
2.Spring 配置 quartz-config.xml
01 | <? xml version = "1.0" encoding = "UTF-8" ?> |
02 | < beans xmlns = "http://www.springframework.org/schema/beans" |
03 | xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns:jee = "http://www.springframework.org/schema/jee" |
04 | xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd |
05 | http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd"> |
10 | class = "org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor" > |
11 | < property name = "corePoolSize" value = "10" /> |
12 | < property name = "maxPoolSize" value = "100" /> |
13 | < property name = "queueCapacity" value = "500" /> |
17 | < bean id = "quartzJob" class = "QuartzJob" ></ bean > |
23 | class = "org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean" > |
25 | < property name = "targetObject" ref = "quartzJob" /> |
27 | < property name = "targetMethod" value = "work1" /> |
31 | class = "org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean" > |
33 | < property name = "targetObject" ref = "quartzJob" /> |
35 | < property name = "targetMethod" value = "work2" /> |
39 | < bean id = "doTime1" class = "org.springframework.scheduling.quartz.CronTriggerBean" > |
40 | < property name = "jobDetail" ref = "jobtask1" /> |
42 | < property name = "cronExpression" value = "0/3 * * * * ?" /> |
45 | < bean id = "doTime2" class = "org.springframework.scheduling.quartz.CronTriggerBean" > |
46 | < property name = "jobDetail" ref = "jobtask2" /> |
47 | < property name = "cronExpression" value = "0/5 * * * * ?" /> |
51 | < bean id = "startQuertz" lazy-init = "false" autowire = "no" |
52 | class = "org.springframework.scheduling.quartz.SchedulerFactoryBean" > |
53 | < property name = "triggers" > |
55 | < ref bean = "doTime1" /> |
56 | < ref bean = "doTime2" /> |
60 | < property name = "taskExecutor" ref = "executor" /> |
3.加载 <!-- 加载spring -->
2 | < param-name >contextConfigLocation</ param-name > |
4 | /WEB-INF/classes/quartz-config.xml |