• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

使用threadPoolExecutor 报错Consider defining a bean of type ‘java.util.concurrent.ThreadPoolExecutor‘ i

武飞扬头像
肥胖飞兔侠
帮助5

Consider defining a bean of type ‘java.util.concurrent.ThreadPoolExecutor’ i

学新通

最近又一个需求,写点击商品进去里面的商品详情页面我来写,因为涉及很多数据接口的组合,我用了异步编排CompletableFuture来做 需要注入线程池,微服务启动时候报错:

@Resource
    private ThreadPoolExecutor threadPoolExecutor;

原因是我注入线程池没有写配置bean信息
解决是:两个方法就可以了:

懒方法:
在你的springboot启动类里面:

    //    //懒行为  创建对象并放到Spring容器中
    @Bean
    public ThreadPoolExecutor threadPoolExecutor() {
        return new ThreadPoolExecutor(10,
                20,
                60L,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(10));
    }

或者是写一个配置类:


@Configuration
public class ThreadConfig {
    @Bean
    public ThreadPoolExecutor threadPoolExecutor() {
        return new ThreadPoolExecutor(10,
                20,
                60L,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(10));
    }
}

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhfhiekf
系列文章
更多 icon
同类精品
更多 icon
继续加载