spring-定时器-QuartzJobBean

java 代码:

 

  1. import org.quartz.JobExecutionContext;  
  2. import org.quartz.JobExecutionException;  
  3. import org.springframework.scheduling.quartz.QuartzJobBean;  
  4.   
  5. public class TestJobBean extends QuartzJobBean {  
  6.   
  7.     @Override  
  8.     protected void executeInternal(JobExecutionContext arg0) throws JobExecutionException {  
  9.         // TODO Auto-generated method stub  
  10.         System.out.println("TestJobBean..run................");  
  11.     }  
  12.   
  13. }  

  1. 配置文件中加入:  
  2. <bean id="reportJob"   
  3.        class="org.springframework.scheduling.quartz.JobDetailBean">   
  4.     <property name="jobClass">   
  5.       <value>com.zhouxf.quartz.TestJobBean</value>   
  6.     </property>    
  7.   </bean>   
  8.     
  9.     <!--定时器设定(0/2 43 12-17 * * ?在121743分,每隔2秒运行一次)-->  
  10.     <bean id="cronReportTrigger2"  
  11.         class="org.springframework.scheduling.quartz.CronTriggerBean">  
  12.         <property name="jobDetail">  
  13.             <ref bean="reportJob" />  
  14.         </property>  
  15.         <property name="cronExpression">  
  16.             <value>0/1 31 12-17 * * ?</value>  
  17.         </property>  
  18.     </bean>  
  19. <!-- 启动定时器 -->
  20. <bean name="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
  21. <property name="applicationContextSchedulerContextKey">  
  22.             <value>applicationContext</value>    
  23.         </property>
  24. <property name="triggers">   
  25.         <list><ref bean="cronReportTrigger2"/></list>   
  26.     </property> 
  27. </bean>

测试代码:

  1. public static void main(String[] args) throws BeansException, FileNotFoundException, InterruptedException {  
  2.         // new LogInit("WEB-INF/classes/com/spring/helloworld/log4j.properties");  
  3.         BeanFactory factory = new XmlBeanFactory(  
  4.                                                  new FileSystemResource(  
  5.                                                                         "///home/zhouxf/work/WebPro/WebContent/WEB-INF/bean.xml"));  
  6.         factory.getBean("test");  
  7.         factory.getBean("test2  
  8.     }  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值