quartz的详细配置可参考:
http://g4-gc.iteye.com/blog/1740123
例子:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.0.xsd"
default-lazy-init="false">
<bean id="passwordupdater" class="com.test.PasswordUpdater">
</bean>
<bean id="testJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="passwordupdater" /> <!-- 定时器的类 -->
<property name="targetMethod" value="process" /> <!-- 指定定时执行的方法 -->
<property name="concurrent" value="false" />
</bean>
<bean id="testJobDetailTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail"><ref bean="testJobDetail"/></property> <!-- 定时JOB-->
<property name="cronExpression"><value>0 0 4 1,15 * ?</value></property> <!--定时计划 -->
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean" destroy-method="destroy">
<property name="waitForJobsToCompleteOnShutdown"><value>true</value></property>
<property name="triggers">
<list>
<ref bean="testJobDetailTrigger"/>
</list>
</property>
<property name="quartzProperties">
<props>
<prop key="org.quartz.threadPool.threadCount">1</prop>
<prop key="org.quartz.scheduler.threadsInheritContextClassLoaderOfInitializer">true</prop>
</props>
</property>
</bean>
</beans>
package com.test;
public class PasswordUpdater {
//定时调用的方法
public void process(){
prepare();
doUpdate();
}
public void prepare(){
System.out.println("perpare...");
}
public void doUpdate(){
System.out.println("do update...");
}
}
package com.test;
public class WebTermApplicationUtil {
//本质就是加载applicationContext-quartz.xml里的定时器定时处理更新密码的任务
private static String[] beanXML = {"applicationContext-quartz.xml"};
private static ApplicationContext ac ;
public static void init(boolean isRunOnce){
ac = new ClassPathXmlApplicationContext(beanXMLOnce);
}
public static Object getApplicationBean(String beanName){
return ac.getBean(beanName);
}
}
package com.test;
public class App
{
public static void main( String[] args ){
WebTermApplicationUtil.init(false);
}
}