• 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); } ); } }
  • 相关阅读:
    Memcached 笔记与总结(4)memcache 扩展的使用
    Excel函数学习:HLOOKUP函数
    因子分析spss怎么做 spss因子分析教程及结果解释
    因子分析spss怎么做 spss因子分析教程及结果解释
    R语言中如何使用最小二乘法
    R语言中如何使用最小二乘法
    SPSS详细操作:样本均数间的多重比较
    SPSS详细操作:样本均数间的多重比较
    从萌芽到绽放 大数据释放大能量
    从萌芽到绽放 大数据释放大能量
  • 原文地址:https://www.cnblogs.com/notchangeworld/p/12188256.html
Copyright © 2020-2023  润新知