zoukankan      html  css  js  c++  java
  • springboot定时任务 多线程/周期自定义

    package cn.com.rivercloud.config;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.scheduling.TaskScheduler;
    import org.springframework.scheduling.annotation.Async;
    import org.springframework.scheduling.annotation.EnableAsync;
    import org.springframework.scheduling.annotation.EnableScheduling;
    import org.springframework.scheduling.annotation.SchedulingConfigurer;
    import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
    import org.springframework.scheduling.config.ScheduledTaskRegistrar;
    import org.springframework.scheduling.support.CronTrigger;
    
    import java.util.concurrent.Executor;
    import java.util.concurrent.Executors;
    
    /**
     * author 
     * date 2020/1/13 0013 16:36
     */
    
    @Configuration
    @EnableScheduling
    public class ScheduledConfig implements SchedulingConfigurer {
    
        @Override
        public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
    
         //线程池的配置 scheduledTaskRegistrar.setScheduler(Executors.newScheduledThreadPool(
    3));
         //并行的三个方法 scheduledTaskRegistrar.addTriggerTask(
              //执行的任务 ()
    -> System.out.println(Thread.currentThread().getName() +"bbbbbbbb"),
              //自定义周期
              triggerContext
    -> { String cron = "0/1 * * * * ?"; return new CronTrigger(cron).nextExecutionTime(triggerContext); } ); scheduledTaskRegistrar.addTriggerTask( ()-> System.out.println(Thread.currentThread().getName() +"aaaaaaaa"), triggerContext -> { String cron = "0/1 * * * * ?"; return new CronTrigger(cron).nextExecutionTime(triggerContext); } ); scheduledTaskRegistrar.addTriggerTask( ()-> System.out.println(Thread.currentThread().getName() +"dddddddd"), triggerContext -> { String cron = "0/1 * * * * ?"; return new CronTrigger(cron).nextExecutionTime(triggerContext); } ); } }
  • 相关阅读:
    Fragment中获取Activity的Context (转)
    raw cannot be resolved or is not a field解决办法
    商业分析07_06分布情况分析
    商业分析07_04漏斗分析
    商业分析07_03数据涨跌异动如何处理
    商业分析07_02多维度拆解
    商业分析07_01对比分析
    商业分析07_00概述 数据分析
    商业分析06选择数据工具
    商业分析05如何选取数据指标
  • 原文地址:https://www.cnblogs.com/notchangeworld/p/12188256.html
Copyright © 2011-2022 走看看