目录
1.1、HystrixCommandGroupKey.Factory.asKey("ServiceGroup"):
2.2、HystrixCommandKey.Factory.asKey("servcie1query")
2.3、HystrixThreadPoolKey.Factory.asKey("service1ThreadPool")
2.4、HystrixThreadPoolProperties.Setter() .withCoreSize(20)
一、初始化参数
super(
Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("ServiceGroup"))
.andCommandKey(HystrixCommandKey.Factory.asKey("servcie1query"))
.andThreadPoolKey(HystrixThreadPoolKey.Factory.asKey("service1ThreadPool"))
.andThreadPoolPropertiesDefaults(HystrixThreadPoolProperties.Setter()
.withCoreSize(20))//服务线程池数量
.andCommandPropertiesDefaults(HystrixCommandProperties.Setter()
.withCircuitBreakerErrorThresholdPercentage(60)//熔断器关闭到打开阈值
.withCircuitBreakerSleepWindowInMilliseconds(3000)//熔断器打开到关闭的时间窗长度
));
1.1、HystrixCommandGroupKey.Factory.asKey("ServiceGroup"):
功能:初始化创建一个Command组
过程:在Hystrix中初始化数据都是用了InternMap<String, HystrixCommandGroupDefault> intern来创建,
intern工具做了防止重复校验。
private final ConcurrentMap<K, V> storage = new ConcurrentHashMap<K, V>();
public V interned(K key) {
V existingKey = storage.get(key);
V newKey = null;
if (existingKey == null) {
newKey = valueConstructor.create(key);
existingKey = storage.putIfAbsent(key, newKey);
}
return existingKey != null ? existingKey : newKey;
}
从中可以看出从了线程安全的storage记录每一个commandGroup,避免了重复重复创建
其实创建成功的HystrixCommandGroupDefault 实体中只有一个name属性,其他啥也没有
2.2、HystrixCommandKey.Factory.asKey("servcie1query")
功能:初始化一个命名名称
过程:像命令组添加命令,初始化原理和1.1一样
2.3、HystrixThreadPoolKey.Factory.asKey("service1ThreadPool")
功能:初始化一个线程池名称
过程:认同1.1一样
2.4、HystrixThreadPoolProperties.Setter() .withCoreSize(20)
功能:初始化线程池参数
过程:线程池中HystrixThreadPoolProperties.Setter()为线程池中的所有课设置参数
二、同步执行
(1)创建待执行的任务,返回值Future