读书人

spring quartz配备定时器

发布时间: 2012-09-08 10:48:07 作者: rapoo

spring quartz配置定时器

1.applicationContext.xml


<?xml version="1.0" encoding="UTF-8"?> ? ? ? ? ? ? ? ? ??

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans> ??

?<!--起动Bean-->


? <bean id="test" ? ?/>

? ? ? ? ? ? ? ? ? ? ? ? </list>

? ? ? ? ? </property>

? </bean>


<!--实际的工作Bean-->

<bean id="testjobbean" />

? ? ? ?</property>

? ? ? <property name="targetMethod">

? ? ? ? ? ? ? ? ? ? <value>run</value>

? ? ?</property>

</bean>


<!--定时器设定(0/2 43 12-17 * * ?在12-17点43分,每隔2秒运行一次)-->


<bean id="cronReportTrigger" ?/>

? ? ? </property>

? ? ? <property name="cronExpression">

? ? ? ? ? ? <value>0/2 43 12-17 * * ?</value>

? ? ? </property>

</bean>

</beans>



?2.创建类 TestJobBean


public class TestJobBean{

? ? public void run() {

? ? ? ? System.out.println("run..................");

? ? }

}


3..获取bean测试:


?public static void main(String[] args) throws BeansException, FileNotFoundException, InterruptedException {

? ? ? ? BeanFactory factory = new XmlBeanFactory( ?new FileSystemResource( ? "///home/zhouxf/work/WebPro/WebContent/WEB-INF/bean.xml"));

? ? ? ? factory.getBean("test");

? ? }


?转自:http://hacker-zxf.javaeye.com/blog/296554


读书人网 >软件开发

热点推荐