Hystrix支持的动态配置列表如下:
- Command Properties
- Collapser Properties
- Thread Pool Properties
/**
* Semaphore that only supports tryAcquire and never blocks and that supports a dynamic permit count.
* <p>
* Using AtomicInteger increment/decrement instead of java.util.concurrent.Semaphore since we don't need blocking and need a custom implementation to get the dynamic permit count and since
* AtomicInteger achieves the same behavior and performance without the more complex implementation of the actual Semaphore class using AbstractQueueSynchronizer.
*/
/* package */static class TryableSemaphoreActual implements TryableSemaphore {
protected final HystrixProperty<Integer> numberOfPermits;
private final AtomicInteger count = new AtomicInteger(0);
public TryableSemaphoreActual(HystrixProperty<Integer> numberOfPermits) {
this.numberOfPermits = numberOfPermits;
}
@Override
public boolean tryAcquire() {
int currentCount = count.incrementAndGet();
if (currentCount > numberOfPermits.get()) {
count.decrementAndGet();
return false;
} else {
return true;
}
}
@Override
public void release() {
count.decrementAndGet();
}
@Override
public int getNumberOfPermitsUsed() {
return count.get();
}
}
com.netflix.hystrix.HystrixThreadPool.HystrixThreadPoolDefault
// allow us to change things via fast-properties by setting it each time
private void touchConfig() {
final int dynamicCoreSize = properties.coreSize().get();
threadPool.setCorePoolSize(dynamicCoreSize);
threadPool.setMaximumPoolSize(dynamicCoreSize); // we always want maxSize the same as coreSize, we are not using a dynamically resizing pool
threadPool.setKeepAliveTime(properties.keepAliveTimeMinutes().get(), TimeUnit.MINUTES); // this doesn't really matter since we're not resizing
}
相关源码类:
com.netflix.hystrix.HystrixThreadPoolProperties
com.netflix.hystrix.HystrixThreadPool
com.netflix.hystrix.HystrixThreadPool.HystrixThreadPoolDefault
com.netflix.hystrix.HystrixThreadPool.HystrixThreadPoolDefault.touchConfig()
com.netflix.hystrix.config.HystrixCommandConfiguration.sample(HystrixCommandKey, HystrixThreadPoolKey, HystrixCommandGroupKey, HystrixCommandProperties)
com.netflix.hystrix.AbstractCommand.getExecutionSemaphore()
com.netflix.hystrix.strategy.properties.HystrixPropertiesFactory.getCommandProperties(HystrixCommandKey, Setter)
com.netflix.hystrix.AbstractCommand.TryableSemaphoreActual<R>
com.netflix.hystrix.HystrixCommandProperties
com.netflix.hystrix.AbstractCommand<R>
com.netflix.hystrix.HystrixCollapserProperties
https://github.com/Netflix/Hystrix/wiki/Configuration#CommandProperties
http://www.iocoder.cn/Hystrix/command-execute-first-run/