在项目中增加task定时任务
生活随笔
收集整理的這篇文章主要介紹了
在项目中增加task定时任务
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1.新建task類
package net.qdedu.task;import lombok.extern.slf4j.Slf4j; import net.qdedu.activity.service.ActivityBaseService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service;@Service @Slf4j public class WeeHoursTask {@Autowiredprivate ActivityBaseService activityBaseService;/***檢測(cè)活動(dòng)是否到開始時(shí)間*/public void collectKnowledgeAbilityData() {log.warn("start");activityBaseService.batchUpdateStartStatus();}/*** 檢測(cè)活動(dòng)是否到結(jié)束時(shí)間*/public void collectWorkGradeData() {log.warn("stop");activityBaseService.batchUpdateStopStatus();}}?
2.增加配置文件spring-task.xml
定時(shí)時(shí)間了解推薦:https://blog.csdn.net/u012843873/article/details/72957965
我們使用的是spring內(nèi)置的定時(shí)任務(wù)
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xmlns:task="http://www.springframework.org/schema/task"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsdhttp://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.3.xsd"default-lazy-init="true"><context:annotation-config /><!--spring掃描注解的配置--><context:component-scan base-package="net.qdedu.task" />//新建項(xiàng)目包的掃描路徑<!-- 每隔3分鐘執(zhí)行一次 --><task:scheduled-tasks><!-- 檢測(cè)活動(dòng)是否到結(jié)束時(shí)間 每50秒執(zhí)行一次 ref:類的名稱 method:對(duì)應(yīng)類的方法--><task:scheduled ref="weeHoursTask" method="collectWorkGradeData" initial-delay="50000" fixed-delay="50000"/> <!-- 檢測(cè)活動(dòng)是否到開始時(shí)間 每50秒執(zhí)行一次 ref:類的名稱 method:對(duì)應(yīng)類的方法--><task:scheduled ref="weeHoursTask" method="collectKnowledgeAbilityData" initial-delay="50000" fixed-delay="50000"/></task:scheduled-tasks></beans>?3.在spring-context.xml增加掃描spring-task.xml
?
轉(zhuǎn)載于:https://www.cnblogs.com/houpengwei/p/10905520.html
總結(jié)
以上是生活随笔為你收集整理的在项目中增加task定时任务的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: LeetCode Implement T
- 下一篇: 灯光问题