zoukankan      html  css  js  c++  java
  • 定时任务,执行时间动态配置方式

    如果配置内容不在application.yml或application.properties,则需要在类上注解

    @PropertySource(value = "classpath:task.properties",encoding = "UTF-8")


    具体执行的方法上写这个
    @Scheduled(cron="${Task_expireOTCAdsState_cron}") 


    import java.util.Date;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.context.annotation.PropertySource;
    import org.springframework.scheduling.annotation.Scheduled;
    import org.springframework.stereotype.Component;
    
    
    @Component
    @PropertySource(value = "classpath:task.properties",encoding = "UTF-8")
    public class QuartzService {
        
        @Autowired
        private OTCAdsService otcAdsService;
        
        
        /**
         * 定时任务更新广告过期
         */
        @Scheduled(cron="${Task_expireOTCAdsState_cron}") 
    //    @Scheduled(cron = "0 0/1 * * * ?")
        public void expireOTCAdsState(){
            LogUtils.info(this.getClass(), "广告过期执行开始:");
            
            LogUtils.info(this.getClass(), "广告过期执行行数:" + count);
            LogUtils.info(this.getClass(), "广告过期执行结束:");
        }
    
    }

    task.properties

    # 任务执行时间cron配置
    Task_expireOTCAdsState_cron=0 0/1 * * * ?
  • 相关阅读:
    [BJOI2019] 光线
    [BJOI2019]奥术神杖
    [HNOI2014]江南乐
    [SDOI2018]荣誉称号
    [APIO2015]雅加达的摩天楼
    [TJOI2015]线性代数
    【CF163E 】e-Government
    【CF917D】Stranger Trees
    网络流(四)dinic算法
    网络流(三)最大流最小割定理
  • 原文地址:https://www.cnblogs.com/shihaiming/p/9453296.html
Copyright © 2011-2022 走看看