错误:java.lang.RuntimeException:could not acquire a semaphore for execution

2022-06-26 09:26:23

最近对接口进行压测,发现只要超过10个线程就报错,都是11个线程请求就报下面的错:

于是查看后台日志,定位错误日志如下:

大致可以看出是hystrix的问题,于是百度hystrix的相关配置,详细配置:https://github.com/Netflix/Hystrix/wiki/Configuration

hystrix有两种策略:

  • THREAD   —     它在单独的线程上执行,并发请求受线程池中线程数的限制
  • SEMAPHORE —     它在调用线程上执行,并发请求受信号量限制

看到其中:

默认10个线程,当然第11个就报错,于是配置文件增加下面的配置:

hystrix.threadpool.default.coreSize=100
hystrix.threadpool.default.maxQueueSize=1500
hystrix.threadpool.default.queueSizeRejectionThreshold=1000
hystrix.command.default.execution.timeout.enabled=false
hystrix.command.default.execution.isolation.strategy=THREAD

问题解决。

  • 作者:沙滩de流沙
  • 原文链接:https://imok520.blog.csdn.net/article/details/105238389
    更新时间:2022-06-26 09:26:23