一个简单的任务调度实例
spring 配置
<!-- 要调度的对象 -->
<bean id="testQuarz" class="com.sy.test.Display" />
<bean id="quartzDetail"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject">
<ref bean="testQuarz" />
</property>
<property name="targetMethod">
<value>disp</value>
</property>
<property name="concurrent" value="false" />
</bean>
<bean id="simpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
<!-- see the example of method invoking job above -->
<property name="jobDetail" ref="quartzDetail" />
<!-- 10秒后开始启动 -->
<property name="startDelay" value="10000" />
<!-- 每10秒重复一次 -->
<property name="repeatInterval" value="10000" />
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="simpleTrigger" />
<!-- <ref bean="cronTrigger" /> -->
</list>
</property>
</bean>
java代码
/**
* @{#} 类名称: Display.java
* 创建时间: Aug 26, 2009 9:52:16 AM
*
*/
package com.sy.test;
import java.util.Date;
/**
* @作者 <a href="http://qing393260529.iteye.com">昨夜风</a>
* @版本 1.0
*/
public class Display {
public void disp(){
System.out.println(new Date().toString());
System.out.println("-------------------------");
}
}
/**
* @{#} 类名称: AutoRun.java
* 创建时间: Aug 26, 2009 9:57:14 AM
*
*/
package com.sy.test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @作者 <a href="http://qing393260529.iteye.com">昨夜风</a>
* @版本 1.0
*/
public class AutoRun {
public static void main(String[] args) {
// 只要加载配置文件就可以了,
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
System.out.println("*****完毕******");
}
}