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;
    	}
    }
    

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

  • 相关阅读:
    习题4.7利用vector实现数据复制
    习题4.18
    4.8编写一小段程序实现两vector是否相等的比较
    关于野指针
    学习c++的50条忠告
    c++头文件
    习题4.14
    容器和迭代器
    Android上C++对象的自动回收机制分析
    Windows下载Android源码
  • 原文地址:https://www.cnblogs.com/timeout/p/10478274.html
Copyright © 2011-2022 走看看