Skip to content

Commit

Permalink
Fix Exception in HystrixThreadPoolDefault.touchConfig() on Java 11
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
michaelnelson123 committed Nov 12, 2022
1 parent 3cb2158 commit 7f8007f
Showing 1 changed file with 12 additions and 2 deletions.
Expand Up @@ -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);
Expand Down

0 comments on commit 7f8007f

Please sign in to comment.