eureka客户端启动流程

本文详细介绍了Eureka客户端的启动流程,包括获取服务端地址、初始化延时任务,如定时获取服务列表、发送心跳和服务注册。客户端通过动态调整任务时间实现定时任务,并在配置更新时重新注册以保持与服务端同步。
摘要由CSDN通过智能技术生成

1. 获取eureka服务端的地址

com.netflix.discovery.endpoint.EndpointUtils#getServiceUrlsFromDNS

2. 初始化延时任务

初始化任务位于这个方法中:com.netflix.discovery.DiscoveryClient#initScheduledTasks
把延迟任务封装到这个类里面com.netflix.discovery.TimedSupervisorTask#TimedSupervisorTask,
使得每个定时任务运行结束后根据运行时间动态调整下次启动任务的时间,既起到了定时任务的作用,又起到了动态调整启动任务的时间。

public void run() {
        Future future = null;
        try {
            future = executor.submit(task);
            threadPoolLevelGauge.set((long) executor.getActiveCount());
            future.get(timeoutMillis, TimeUnit.MILLISECONDS);  // block until done or timeout
            delay.set(timeoutMillis);
            threadPoolLevelGauge.set((long) executor.getActiveCount());
        } catch (TimeoutException e) {
            logger.error("task supervisor timed out", e);
            timeoutCounter.increment();
			//如果当前任务超时,获取超时时间*2或者最大延时时间中的最大值,作为下次的延时启动时间。
            long currentDelay = delay.get();
            long newDelay = Math.min(maxDelay, currentDelay * 2);
            delay.compareAndSet(currentDelay, newDelay);

        } catch (RejectedExecutionException e) {
            if (executor.isShutdown() || scheduler.isShutdown()) {
                logger.warn("task supervisor shutting down, reject the task", e);
            } else {
                logger.error("task supervisor rejected the task", e);
            }

            rejectedCounter.increment();
        } catch (Throwable e) {
            if (executor.isShutdown() || scheduler.isShutdown()) {
                logger.warn("task supervisor shutting down, can't accept the task");
           
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值