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 * * * ?
  • 相关阅读:
    SQL注入方法之:获取列名
    手把手教会你模拟退火算法
    我的G++编译选项
    编译器优化误解程序员的意思
    ZKW线段树
    扩展欧几里得算法
    快速幂
    乘法取模
    莫队算法良心讲解
    高精度模板
  • 原文地址:https://www.cnblogs.com/shihaiming/p/9453296.html
Copyright © 2011-2022 走看看