All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.volcengine.model.tls.util.TimeUtil Maven / Gradle / Ivy

There is a newer version: 1.0.192
Show newest version
package com.volcengine.model.tls.util;

import com.google.common.math.LongMath;

public class TimeUtil {
    private TimeUtil() {
    }

    // 计算重试应该等待的时间间隔
    public static long calcDefaultBackOffMs(int counter, int baseRetryMs, long expectedQuitTimestamp) throws InterruptedException {
        long currentTime = System.currentTimeMillis();
        int randomNum = (int) (Math.random() * counter);
        long sleepTime = (long) randomNum * baseRetryMs;

        if (currentTime + sleepTime < expectedQuitTimestamp) {
            return sleepTime;
        } else {
            return expectedQuitTimestamp - currentTime;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy