【SpringCloud】HystrixCommand的threadPoolKey默认值及线程池初始化 (2)

其中MetaHolder metaHolder = metaHolderFactory.create(joinPoint)根据joinPoint的信息创建元数据时肯定会有初始化默认groupKey默认commandKey以及默认threadPoolKey的逻辑

创建MetaHolder元数据 private static class CommandMetaHolderFactory extends MetaHolderFactory { @Override public MetaHolder create(Object proxy, Method method, Object obj, Object[] args, final ProceedingJoinPoint joinPoint) { HystrixCommand hystrixCommand = method.getAnnotation(HystrixCommand.class); ExecutionType executionType = ExecutionType.getExecutionType(method.getReturnType()); // 创建MetaHolderBuilder MetaHolder.Builder builder = metaHolderBuilder(proxy, method, obj, args, joinPoint); if (isCompileWeaving()) { builder.ajcMethod(getAjcMethodFromTarget(joinPoint)); } return builder.defaultCommandKey(method.getName()) //默认commandKey是方法名 .hystrixCommand(hystrixCommand) .observableExecutionMode(hystrixCommand.observableExecutionMode()) .executionType(executionType) .observable(ExecutionType.OBSERVABLE == executionType) .build(); } } //----------再来看看创建MetaHolderBuilder - metaHolderBuilder() //== MetaHolderFactory#metaHolderBuilder() MetaHolder.Builder metaHolderBuilder(Object proxy, Method method, Object obj, Object[] args, final ProceedingJoinPoint joinPoint) { MetaHolder.Builder builder = MetaHolder.builder() .args(args).method(method).obj(obj).proxyObj(proxy) .joinPoint(joinPoint); // 设置fallback方法 setFallbackMethod(builder, obj.getClass(), method); // 设置默认配置 builder = setDefaultProperties(builder, obj.getClass(), joinPoint); return builder; } //== 设置默认配置 setDefaultProperties() private static MetaHolder.Builder setDefaultProperties(MetaHolder.Builder builder, Class<?> declaringClass, final ProceedingJoinPoint joinPoint) { //根据@DefaultProperties注解获取配置 Optional<DefaultProperties> defaultPropertiesOpt = AopUtils.getAnnotation(joinPoint, DefaultProperties.class); //设置 默认groupKey为类名simpleName builder.defaultGroupKey(declaringClass.getSimpleName()); //如果存在@DefaultProperties,使用其指定的groupKey、threadPoolKey if (defaultPropertiesOpt.isPresent()) { DefaultProperties defaultProperties = defaultPropertiesOpt.get(); builder.defaultProperties(defaultProperties); if (StringUtils.isNotBlank(defaultProperties.groupKey())) { builder.defaultGroupKey(defaultProperties.groupKey()); } if (StringUtils.isNotBlank(defaultProperties.threadPoolKey())) { builder.defaultThreadPoolKey(defaultProperties.threadPoolKey()); } } return builder; }

由此可见,在构造metaHolder元数据时,通过@HystrixCommand标准方法所在的类名作为goutpKey,通过方法名作为commandKey,但没有指定threadPoolKey

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zygxjz.html