【14】分析隔离线程池的线程隔离threadPool.getScheduler的初始化【位于第六步里面】
private static HystrixThreadPool initThreadPool(HystrixThreadPool fromConstructor, HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolProperties.Setter threadPoolPropertiesDefaults) {if (fromConstructor == null) {// get the default implementation of HystrixThreadPool//通过塞入注解信息threadPoolPropertiesDefaults进行初始化return HystrixThreadPool.Factory.getInstance(threadPoolKey, threadPoolPropertiesDefaults);} else {return fromConstructor;}}static HystrixThreadPool getInstance(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolProperties.Setter propertiesBuilder) {// get the key to use instead of using the object itself so that if people forget to implement equals/hashcode things will still workString key = threadPoolKey.name();// this should find it for all but the first timeHystrixThreadPool previouslyCached = threadPools.get(key);if (previouslyCached != null) {return previouslyCached;}// if we get here this is the first time so we need to initializesynchronized (HystrixThreadPool.class) {if (!threadPools.containsKey(key)) {threadPools.put(key, new HystrixThreadPoolDefault(threadPoolKey, propertiesBuilder));}}return threadPools.get(key);}public HystrixThreadPoolDefault(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolProperties.Setter propertiesDefaults) {this.properties = HystrixPropertiesFactory.getThreadPoolProperties(threadPoolKey, propertiesDefaults);HystrixConcurrencyStrategy concurrencyStrategy = HystrixPlugins.getInstance().getConcurrencyStrategy();this.queueSize = properties.maxQueueSize().get();this.metrics = HystrixThreadPoolMetrics.getInstance(threadPoolKey,concurrencyStrategy.getThreadPool(threadPoolKey, properties),properties);this.threadPool = this.metrics.getThreadPool();this.queue = this.threadPool.getQueue();/* strategy: HystrixMetricsPublisherThreadPool */HystrixMetricsPublisherFactory.createOrRetrievePublisherForThreadPool(threadPoolKey, this.metrics, this.properties);}【15】断路器初始化分析【位于第六步里面】
private static HystrixCircuitBreaker initCircuitBreaker(boolean enabled, HystrixCircuitBreaker fromConstructor,HystrixCommandGroupKey groupKey, HystrixCommandKey commandKey,HystrixCommandProperties properties, HystrixCommandMetrics metrics) {// 如果启用了熔断器if (enabled) {// 若commandKey没有对应的CircuitBreaker,则创建if (fromConstructor == null) {// get the default implementation of HystrixCircuitBreakerreturn HystrixCircuitBreaker.Factory.getInstance(commandKey, groupKey, properties, metrics);} else {// 如果有则返回现有的return fromConstructor;}} else {return new NoOpCircuitBreaker();}}//circuitBreaker以commandKey为维度,每个commandKey都会有对应的circuitBreakerpublic static HystrixCircuitBreaker getInstance(HystrixCommandKey key, HystrixCommandGroupKey group, HystrixCommandProperties properties, HystrixCommandMetrics metrics) {// 如果有则返回现有的, key.name()即command的name作为检索条件HystrixCircuitBreaker previouslyCached = circuitBreakersByCommand.get(key.name());if (previouslyCached != null) {return previouslyCached;}// 如果没有则创建并cacheHystrixCircuitBreaker cbForCommand = circuitBreakersByCommand.putIfAbsent(key.name(), new HystrixCircuitBreakerImpl(key, group, properties, metrics));if (cbForCommand == null) {// this means the putIfAbsent step just created a new one so let's retrieve and return itreturn circuitBreakersByCommand.get(key.name());} else {// this means a race occurred and while attempting to 'put' another one got there before// and we instead retrieved it and will now return itreturn cbForCommand;}}protected HystrixCircuitBreakerImpl(HystrixCommandKey key, HystrixCommandGroupKey commandGroup, HystrixCommandProperties properties, HystrixCommandMetrics metrics) {this.properties = properties;this.metrics = metrics;}Hystrix源码分析图
文章插图
MetaHolder
推荐阅读
- 王者荣耀9月27日微信每日一题答案分享
- 如何修改微信开机密码(微信原密码忘了如何重新设置密码)
- 11 微服务架构学习与思考:开源 API 网关02-以 Java 为基础的 API 网关详细介绍
- 如何修改微信密码(怎样修改微信密码教程)
- 如何重新设定微信密码(微信密码8-16位)
- 微信独立密码怎么改(微信登录新手机三天不能改密码)
- 怎么修改微信号,怎么修改微信密码(微信修改微信号的方法)
- 微信怎么修改密码,如何修改微信密码(微信手势密码忘了进不了微信)
- 我的微信密码怎么修改(微信为了账号安全暂不能修改密码)
- 怎样修改微信加密密码(微信如何加密隐藏某个人聊天记录)