適用於無期限數據挖掘。
Quartz可以用來創建簡單或爲運行十個,百個,甚至是好幾萬個Jobs這樣複雜的程序
包:quartz-all-1.8.5.jar
配置文件:applicationContext-quartz.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd">
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"
lazy-init="false">
<property name="triggers">
<!--配置所有任務list-->
<list>
<ref local="oneTestJob" /> <!--名字與下面id對應-->
</list>
</property>
</bean>
<!-- 測試調度 -->
<bean id="oneTestJob" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="tvMethodInvokingJob"
/><!--與下面bean id 一致-->
</property>
<property name="cronExpression">
<!-- 15秒一次 -->
<value>*/15 * * * * ?</value>
</property>
</bean>
<bean id="tvMethodInvokingJob"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject">
<ref bean="oneTestBo" /><!--配置bean-->
</property>
<property name="targetMethod">
<value>runJob</value><!--讓它執行runjob方法-->
</property>
</bean>
</beans>
web.xml 配置quartz 的xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext*.xml</param-value>
</context-param>
/**
* @description: 調度測<br>
* @author: jialiuyang
* @update: 2015-7
* @version: 1.0
*/
@Component("oneTestBo")
public class Onetest {
@Autowired
private ICommonService commonService;
@Autowired
protected CommonDAO commonDAO;
private final Logger log = Logger.getLogger(this.getClass());
public synchronized void runJob() {
try {
work();
} catch (Exception e) {
log.error("系統處理失敗", e);
}
}
private void work() {
System.out.println("輪詢調度執行。。。");
}
}
啓動tomcate。。