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); } ); } }
  • 相关阅读:
    set用法
    01分数规划
    unique && stl的全排列
    lower_bound() && upper_bound()
    spfa判负环
    倍增求LCA
    数据生成c++程序模板
    samba
    vsftp快速配置
    grub丢失的修复
  • 原文地址:https://www.cnblogs.com/notchangeworld/p/12188256.html
Copyright © 2011-2022 走看看