From 7f8007f352c91a3136de505e3994727184fe8f09 Mon Sep 17 00:00:00 2001 From: Michael Nelson Date: Fri, 11 Nov 2022 20:05:25 -0700 Subject: [PATCH] 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. --- .../com/netflix/hystrix/HystrixThreadPool.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixThreadPool.java b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixThreadPool.java index c68641dbf..7ea405b85 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixThreadPool.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixThreadPool.java @@ -227,8 +227,18 @@ private void touchConfig() { dynamicCoreSize + " and maximumSize = " + configuredMaximumSize + ". Maximum size will be set to " + dynamicMaximumSize + ", the coreSize value, since it must be equal to or greater than the coreSize value"); } - threadPool.setCorePoolSize(dynamicCoreSize); - threadPool.setMaximumPoolSize(dynamicMaximumSize); + // In JDK 11, setCorePoolSize will not allow a value greater than the current maximumPoolSize. + if (dynamicCoreSize <= threadPool.getMaximumPoolSize()) { + threadPool.setCorePoolSize(dynamicCoreSize); + threadPool.setMaximumPoolSize(dynamicMaximumSize); + } else { + // In JDK 11, setMaximumPoolSize will not allow a value less than the current corePoolSize. + if (dynamicMaximumSize < threadPool.getCorePoolSize()) { + threadPool.setCorePoolSize(1); + } + threadPool.setMaximumPoolSize(dynamicMaximumSize); + threadPool.setCorePoolSize(dynamicCoreSize); + } } threadPool.setKeepAliveTime(properties.keepAliveTimeMinutes().get(), TimeUnit.MINUTES);