日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

在项目中增加task定时任务

發(fā)布時間:2025/3/21 46 豆豆
生活随笔 收集整理的這篇文章主要介紹了 在项目中增加task定时任务 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

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;/***檢測活動是否到開始時間*/public void collectKnowledgeAbilityData() {log.warn("start");activityBaseService.batchUpdateStartStatus();}/*** 檢測活動是否到結(jié)束時間*/public void collectWorkGradeData() {log.warn("stop");activityBaseService.batchUpdateStopStatus();}}

?

2.增加配置文件spring-task.xml

定時時間了解推薦:https://blog.csdn.net/u012843873/article/details/72957965

我們使用的是spring內(nèi)置的定時任務(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" />//新建項目包的掃描路徑<!-- 每隔3分鐘執(zhí)行一次 --><task:scheduled-tasks><!-- 檢測活動是否到結(jié)束時間 每50秒執(zhí)行一次 ref:類的名稱 method:對應(yīng)類的方法--><task:scheduled ref="weeHoursTask" method="collectWorkGradeData" initial-delay="50000" fixed-delay="50000"/> <!-- 檢測活動是否到開始時間 每50秒執(zhí)行一次 ref:類的名稱 method:對應(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定时任务的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。