zoukankan      html  css  js  c++  java
  • spring boot 定时任务

    /**
     * Created by Admin on 2016/4/28.
     */
    @Service("flowService")
    @Component
    public class FlowServiceImpl implements FlowService{
    
    
        protected Logger log = LoggerFactory.getLogger(getClass());
    
        @Autowired
        private FlowCountRepository flowCountRepository;
    
        @Autowired
        private ScopConfig scopConfig;
    
        @Override
        @Scheduled(cron = "${scop.exportTime}")
        public  void export1(){
            /**
             * 如果没有文件夹,则创建
             */
            SimpleDateFormat fm=new SimpleDateFormat("yyyyMMddHHmmss");
            String urlName=scopConfig.getFlowCount();
            log.debug("导出文件存放的路劲为"+urlName);
            File file = new File(urlName);
            if (!file.exists()) {
                file.mkdir();
            }

    application.properties 中
    #流量统计定时导出时间 每天12点04执行导出
    scop.exportTime=0 04 12 ? * *

    如果你的项目中,统一时间点有多个定时任务要执行,那么就可能出现一个任务执行时间过长占用线程资源,导致其他任务无法执行。需要加如下的类

    /**
     * Created by zhiqi.shao on 2017/12/7.
     */
    @Slf4j
    @Configuration
    @EnableConfigurationProperties
    @AutoConfigureAfter
    public class TaskConfig  implements SchedulingConfigurer {
    
    
        @Override
        public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
    
        }
    
        @Bean(destroyMethod = "shutdown")
        public ThreadPoolTaskScheduler taskExecutor() {
            ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
            scheduler.setPoolSize(4);
            scheduler.initialize();
            return scheduler;
        }
    }

     

  • 相关阅读:
    接口,抽象类,普通类
    将svn项目导出,再导入到其他工作空间
    Ajax 与 Struts 1
    save tran tranName
    hibernate缓存机制详细分析
    sql中的group by 和 having 用法解析
    TensorBoard 实践 1
    Tensorflow 解决MNIST问题的重构程序
    在MNIST数据集,实现多个功能的tensorflow程序
    Tensorflow中的滑动平均模型
  • 原文地址:https://www.cnblogs.com/shaozhiqi/p/5287987.html
Copyright © 2011-2022 走看看