spring定時器使用

以下是本人另外一種實現方式,跟@Scheduled註解配置有點不一樣
1.在xml里加入task的命名空間
xmlns:task="http://www.springframework.org/schema/task" 
2.在xsi:schemaLocation加
http://www.springframework.org/schema/task 
http://www.springframework.org/schema/task/spring-task-4.3.xsd
3.定時器設置
    <bean name="testTask" class="sy.scheduler.MediaTask" lazy-init="false"></bean>
    <task:scheduled-tasks>   
        <task:scheduled ref="testTask" method="TaskJob" cron="0/2 * * * * ?"/>   
    </task:scheduled-tasks>
4.後臺定時器代碼
package sy.scheduler;

import org.springframework.beans.factory.annotation.Autowired;

import sy.service.AppBusinessServiceI;

public class MediaTask {	
	
    public void TaskJob() { 
	System.out.println("this is timer job...");
    }
}




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