Skip to content

Commit 7f8007f

Browse files
Fix Exception in HystrixThreadPoolDefault.touchConfig() on Java 11
Java 11 ThreadPoolExecutor.setCorePoolSize() throws an IllegalArgumentException if the new coreSize is larger than the current maximumPoolSize. Similarly, setMaximumPoolSize() throws an exception if the new value is less than the current coreSize.
1 parent 3cb2158 commit 7f8007f

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

hystrix-core/src/main/java/com/netflix/hystrix/HystrixThreadPool.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,18 @@ private void touchConfig() {
227227
dynamicCoreSize + " and maximumSize = " + configuredMaximumSize + ". Maximum size will be set to " +
228228
dynamicMaximumSize + ", the coreSize value, since it must be equal to or greater than the coreSize value");
229229
}
230-
threadPool.setCorePoolSize(dynamicCoreSize);
231-
threadPool.setMaximumPoolSize(dynamicMaximumSize);
230+
// In JDK 11, setCorePoolSize will not allow a value greater than the current maximumPoolSize.
231+
if (dynamicCoreSize <= threadPool.getMaximumPoolSize()) {
232+
threadPool.setCorePoolSize(dynamicCoreSize);
233+
threadPool.setMaximumPoolSize(dynamicMaximumSize);
234+
} else {
235+
// In JDK 11, setMaximumPoolSize will not allow a value less than the current corePoolSize.
236+
if (dynamicMaximumSize < threadPool.getCorePoolSize()) {
237+
threadPool.setCorePoolSize(1);
238+
}
239+
threadPool.setMaximumPoolSize(dynamicMaximumSize);
240+
threadPool.setCorePoolSize(dynamicCoreSize);
241+
}
232242
}
233243

234244
threadPool.setKeepAliveTime(properties.keepAliveTimeMinutes().get(), TimeUnit.MINUTES);

0 commit comments

Comments
 (0)