Maven
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>1.8.6</version>
</dependency>
<dependency>
<groupId>org.fusesource</groupId>
<artifactId>sigar</artifactId>
<version>1.6.4</version>
</dependency>
web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/config/applicationContext-base.xml;
/WEB-INF/config/applicationContext-quartz.xml;
</param-value>
</context-param>
applicationContext-quartz.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!-- 定时任务调度器,负责对所以加入队列的触发器定时触发 -->
<bean id="startQuertz" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<!-- <ref bean="workflowJobTrigger" /> -->
<!-- <ref bean="jobSchedulerTrigger" /> -->
<!-- <ref bean="cpCountSignJobTrigger" /> -->
</list>
</property>
</bean>
<!-- 异步任务调度 -->
<bean id="jobSchedulerTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="jobSchedulerTask" />
<property name="cronExpression">
<!-- 每隔两分钟 -->
<value>0 0/2 * * * ?</value>
</property>
</bean>
<bean id="jobSchedulerTask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="jobScheduler" />
<property name="targetMethod" value="doSchedule" />
<property name="concurrent" value="false" /> <!--将并发设置为false-->
</bean>
<bean id="jobScheduler" class="com.aiso.basic.job.JobInfoScheduler" />
<!-- 轮询 -->
<bean id="cpCountSignJobTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="cpCountSignJobTask" />
<property name="cronExpression">
<value>0 0/5 * * * ?</value>
</property>
</bean>
<bean id="cpCountSignJobTask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="cpCountSignJobScheduler" />
<property name="targetMethod" value="saveCpCountSign" />
<property name="concurrent" value="false" /> <!--将并发设置为false-->
</bean>
<bean id="cpCountSignJobScheduler" class="com.aiso.index.job.CpCountSignJob" />
</beans>
定时执行的类
public class CpCountSignJob {
public void saveCpCountSign() {
if (this.log.isDebugEnabled()) {
this.log.debug("轮询任务开始执行!");
}
//TODO
}
}