spring定時器配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:util="http://www.springframework.org/schema/util" xmlns:mvc="http://www.springframework.org/schema/mvc"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
	xmlns:task="http://www.springframework.org/schema/task"
	xsi:schemaLocation="http://www.springframework.org/schema/beans  
            http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
            http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd
            http://www.springframework.org/schema/mvc
            http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
            http://www.springframework.org/schema/context  
            http://www.springframework.org/schema/context/spring-context-3.0.xsd  
            http://www.springframework.org/schema/tx  
            http://www.springframework.org/schema/tx/spring-tx-3.0.xsd  
            http://www.springframework.org/schema/jdbc  
            http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
            http://www.springframework.org/schema/task   
            http://www.springframework.org/schema/task/spring-task-3.0.xsd">

	<task:executor id="executor" pool-size="5" />
	<task:scheduler id="scheduler" pool-size="10" />
	<task:annotation-driven executor="executor"
		scheduler="scheduler" />

	<bean id="initTask" class="com.ks.common.timerTask.InitSchedul"
		init-method="initSchedul"></bean>

</beans>

執行InitSchedul類中的initSchedul方法.

@Scheduled(cron = "0 30 09/21 * * ?")寫在定時器類中的方法上,便會執行initSchedul方法。

時間的配置如下:
<value>0 26 16 * * ?value>

時間大小由小到大排列,從秒開始,順序爲 秒,分,時,天,月,年    *爲任意 ?爲無限制。

"0 * 14 * * ?" 在每天下午2點到下午2:59期間的每1分鐘觸發

"0 0/5 14 * * ?" 在每天下午2點到下午2:55期間的每5分鐘觸發

"0 0/5 14,18 * * ?" 在每天下午2點到2:55期間和下午6點到6:55期間的每5分鐘觸發

"0 0-5 14 * * ?" 在每天下午2點到下午2:05期間的每1分鐘觸發

"0 10,44 14 ? 3 WED" 每年三月的星期三的下午2:10和2:44觸發

注意: 實現上述功能需加包

quartz-all-1.6.0.jar
jta.jar

發佈了100 篇原創文章 · 獲贊 7 · 訪問量 24萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章