當前使用的版本
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.3.RELEASE</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR7</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
相關依賴
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
<exclusions>
<exclusion>
<groupId>com.netflix.hystrix</groupId>
<artifactId>hystrix-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- 升級版本, keepAliveTimeMinutes 參數在 1.5.9版本以才能使用 -->
<dependency>
<groupId>com.netflix.hystrix</groupId>
<artifactId>hystrix-core</artifactId>
<version>1.5.10</version>
</dependency>
某個服務 feign 接口並發參數,當沒有隊列的情況下
# 最小線程數
hystrix.threadpool.inventory-service.coreSize=5
# 最大線程數
hystrix.threadpool.inventory-service.maximumSize=20
# 線程在被釋放之前將使用多長時間
hystrix.threadpool.inventory-service.keepAliveTimeMinutes=1
# 設為 true ,允許設置最小線程數 和 最大線程數
hystrix.threadpool.inventory-service.allowMaximumSizeToDivergeFromCoreSize=true
結論
在沒有設置隊列的情況下,一共有 25 個並發請求,則 5 個請求會被拒絕,只能一次通過 20 個請求,當 1 分鍾后,則 線程池大小就會變為 5 個。這樣大小coreSize 的線程數就可以釋放調了。