0

有没有办法检索HystrixThreadPoolProperties特定于 a 的实例(或其他一些属性容器)HystrixThreadPoolKey

所以基本上默认线程池属性覆盖了我通过执行以下命令提供的配置:

HystrixCommand.Setter.withGroupKey(<some group>)
    .andThreadPoolKey(hystrixThreadPoolKey)
    .andThreadPoolPropertiesDefaults(...)

我尝试了以下方法:

HystrixPropertiesStrategy hystrixPropertiesStrategy = HystrixPropertiesStrategyDefault.getInstance();

HystrixThreadPoolProperties hystrixThreadPoolProperties =
            hystrixPropertiesStrategy.getThreadPoolProperties(hystrixThreadPoolKey, HystrixThreadPoolProperties.Setter());

这似乎恢复了线程池的默认 Hystrix 配置,但没有恢复我对键对应的特定池所做的任何属性更改。

即使当我执行从线程池运行的命令时,我能够验证线程池确实在获取配置,情况也是如此。

4

1 回答 1

0

我使用的 Hystrix 版本是 1.5.0-rc.5,我无法从库中找到任何允许直接检索与命令关联的线程池属性的内容。所以这是我尝试使用 Java 反射的方法:

    HystrixInvokableInfo<?> command = HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().iterator().next();

    Field field = command.getClass().getSuperclass().getSuperclass().getSuperclass().getDeclaredField("threadPool");
    field.setAccessible(true);
    HystrixThreadPool threadPool = (HystrixThreadPool) field.get(command);

    Field field2 = HystrixThreadPool.HystrixThreadPoolDefault.class.getDeclaredField("properties");
    field2.setAccessible(true);
    HystrixThreadPoolProperties threadPoolProperties = (HystrixThreadPoolProperties) field2.get(threadPool);
于 2016-03-03T10:25:17.963 回答