歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux編程 >> Linux編程

Spring 定時器的應用及表達式解釋

先看applicationContext.xml下面的beans

  1. <!-- Trigger -->  
  2.   
  3.     <bean id="autoJob" class="com.spring.app.AutoJob" />  
  4.   
  5.     <bean id="autoTask" class="com.spring.app.AutoTask" />  
  6.   
  7.     <bean name="autoWeekly" class="org.springframework.scheduling.quartz.JobDetailBean">  
  8.         <property name="jobClass" value="com.spring.app.AutoWeekly" />  
  9.     </bean>  
  10.   
  11.     <bean id="job" class="org.springframework.scheduling.quartz.SimpleTriggerBean">  
  12.   
  13.         <property name="jobDetail" ref="jobDetail" />  
  14.         <property name="startDelay" value="10000" />  
  15.         <property name="repeatInterval" value="50000" />  
  16.     </bean>  
  17.   
  18.     <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">  
  19.         <property name="jobDetail" ref="autoWeekly" />  
  20.         <!-- run every morning at 6 AM -->  
  21.         <property name="cronExpression" value="0 33 18 * * ?" />  
  22.     </bean>  
  23.   
  24.     <bean id="scheduledTask" class="org.springframework.scheduling.timer.ScheduledTimerTask">  
  25.         <!-- wait 10 seconds before starting repeated execution -->  
  26.         <property name="delay" value="1000" />  
  27.         <!-- run every 50 seconds -->  
  28.         <property name="period" value="5000" />  
  29.         <property name="timerTask" ref="autoTask" />  
  30.     </bean>  
  31.     <!-- 使用TimerFactoryBean來設置任務 -->  
  32.     <bean id="timerFactory" class="org.springframework.scheduling.timer.TimerFactoryBean">  
  33.         <property name="scheduledTimerTasks">  
  34.             <list>  
  35.                 <ref bean="scheduledTask" />  
  36.             </list>  
  37.         </property>  
  38.     </bean>  
  39.   
  40.     <bean id="jobDetail"  
  41.         class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">  
  42.         <property name="targetObject" ref="autoJob" />  
  43.         <property name="targetMethod" value="doIt" />  
  44.         <property name="concurrent" value="false" />  
  45.     </bean>  
  46.   
  47.     <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">  
  48.         <property name="triggers">  
  49.             <list>  
  50.                 <ref bean="cronTrigger" />  
  51.                 <ref bean="job" />  
  52.             </list>  
  53.         </property>  
  54.     </bean>  
  55.   
  56.     <!-- Trigger end -->  
Copyright © Linux教程網 All Rights Reserved