定時器quartz結合spring使用(方法一JobDetailBean)

1.quartz版本:1.x建議使用quartz-all-1.8.6.jar;

2.spring版本:2.x,3.x及以上quartz版本需要使用2.x的quartz;

3.配置:

		<!--指定時間運行 
			1.秒(0–59 - * /) 
			2.分鐘(0–59 - * / ) 
			3.小時(0–23 - * / ) 
			4.月份中的日期(1–31 - * ? / L W C )
			5.月份(1–12或JAN–DEC - * / ) 
			6.星期中的日期(1–7或SUN–SAT - * ? / L C #) 
			7.年份(1970–2099  empty, 1970-2099 , - * /) 
		-->  
	
	<bean name="onekey" class="org.springframework.scheduling.quartz.JobDetailBean">  
		<property name="jobClass" value="com.xxx.OnekeyAutoThreadBean" />  
		<property name="jobDataAsMap">  
		<map>  
		<entry key="timeout" value="0" />  
		</map>  
		</property>  
	</bean>  
	<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">  
		<property name="jobDetail" ref="onekey" />  

		<property name="cronExpression" value="0 0 0,12 * * ?" />  
	</bean>
	  
	<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">  
		<property name="triggers">  
		<list>  
		<ref bean="cronTrigger" />  
		</list>  
		</property>  
	</bean>  
任務類:

public class OnekeyAutoThreadBean extends QuartzJobBean {  
  
	private int timeout;  
	private static int i = 0;  
	//調度工廠實例化後,經過timeout時間開始執行調度  
	public void setTimeout(int timeout) {  
		this.timeout = timeout;  
	}  
  
	/** 
	* 要調度的具體任務 
	*/  
	@Override  
	protected void executeInternal(JobExecutionContext context)  throws JobExecutionException {  
	  System.out.println("定時任務執行開始…");  
	  ...
	  System.out.println("定時任務執行結束…");  
	}  
}  



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章