zoukankan      html  css  js  c++  java
  • Spring-Boot中@Scheduled注解不生效

      今天测试来找我,说定时的策略任务不能运行了,或者有时候运行有时候不运行,很奇怪。之前都好好,百思不得其解。

      后来发现多了一个定时任务类,且都是用的@Scheduled注解。

      突然就恍然大悟,记得在哪里看到过,如果在多个函数上使用了@Scheduled,那么一定是一个执行完毕,才能排下一个。

      然后发现某些时间点我的任务会被阻塞。

      以下是两个定时任务类都用了这个注解的图。

      

      解决方法如下,配置线程池,创建一个类配置,如下:

    import java.util.concurrent.ScheduledThreadPoolExecutor;
    
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    
    @Configuration
    public class ThredConfig {
    	@Bean
    	public ScheduledThreadPoolExecutor scheduledExecutorService() {
    		ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(10);
    		return executor;
    	}
    }
    

      这就是我踩的坑,学习的路上任重而道远。如有错漏,欢迎指正。

  • 相关阅读:
    CSS3实现小黄人动画
    CSS3实现时间轴效果
    CSS3实现8种Loading效果【二】
    Delphi面向对象的编程思想
    delphi 格式转换
    FindWindow和FindWindowEx函数使用
    delphi TStringList 用法详解
    ExtractFileDir 与 ExtractFilePath 的区别
    C++模板与群体数据
    C++多态性
  • 原文地址:https://www.cnblogs.com/timeout/p/10478274.html
Copyright © 2011-2022 走看看