zoukankan      html  css  js  c++  java
  • hystrix(5) 延时检测

      hystrix在执行命令的同事,会对执行延时进行检测,如果超过设置的延时时间,那么将停止执行,并返回fallback执行结果。

    if (properties.executionTimeoutEnabled().get()) {
                execution = executeCommandWithSpecifiedIsolation(_cmd)
                        .lift(new HystrixObservableTimeoutOperator<R>(_cmd));
            } else {
                execution = executeCommandWithSpecifiedIsolation(_cmd);
            }

      本质就是开启一个定时器,当到达指定时间时,去检测执行命令是否完成,如果没有完成,则返回异常,外部方法监听异常,执行fallback。

    private static class HystrixObservableTimeoutOperator<R> implements Operator<R, R> {
            final AbstractCommand<R> originalCommand;
            public HystrixObservableTimeoutOperator(final AbstractCommand<R> originalCommand) {
                this.originalCommand = originalCommand;
            }
            @Override
            public Subscriber<? super R> call(final Subscriber<? super R> child) {
                ...
                final HystrixContextRunnable timeoutRunnable = new HystrixContextRunnable(originalCommand.concurrencyStrategy, new Runnable() {
                    @Override
                    public void run() {
                        child.onError(new HystrixTimeoutException());
                    }
                });
                TimerListener listener = new TimerListener() {
    ...
                            timeoutRunnable.run();
                        ...
                        }
                    }
                    @Override
                    public int getIntervalTimeInMilliseconds() {
                        return originalCommand.properties.executionTimeoutInMilliseconds().get();
                    }
                };
                final Reference<TimerListener> tl = HystrixTimer.getInstance().addTimerListener(listener);
               ...
            }
    
        }
  • 相关阅读:
    chgrp,chown,chmod用法
    关于linux文件夹与文件的权限理解
    centos7重置root密码
    Mac 下利用 Launchctl 自启动 mysql
    mac 10.10 下编译php拓展之mcrypt
    [转]使用Google地图API搜索功能
    ajax中获取和发送二进制数据的方法
    samba详解
    wamp You don't have permission to access / on this server等问题的解决.
    Cisco3.3.2.2
  • 原文地址:https://www.cnblogs.com/zhangwanhua/p/8250181.html
Copyright © 2011-2022 走看看