private boolean needsRenew(TokenWrapper token) {
    long now = Time.now();
    long tokenWholeValidityPeriodMs = token.expirationTime - token.renewalTime;
    long tokenRemainingValidityPeriodMs = Math.max(token.expirationTime - now, 0);
    // a number which tells how close is token expiry time, e.g. 0.1 means only 10% of the token validity period left
    double tokenRemainingValidityPeriodPercent = (double) tokenRemainingValidityPeriodMs / tokenWholeValidityPeriodMs;
    boolean needsRenew = tokenRemainingValidityPeriodPercent < 0.1;

    LOG.debug(
        "Token needsRenew? {}, now: {}, expirationTime: {}, renewalTime: {}, tokenWholeValidityPeriod(ms): {},"
            + " tokenRemainingValidityPeriod(ms): {}, tokenRelativeRemainingValidityPeriod: {}%",
        needsRenew, now, token.expirationTime, token.renewalTime, tokenWholeValidityPeriodMs,
        tokenRemainingValidityPeriodMs, toPercentString(tokenRemainingValidityPeriodPercent));
    return needsRenew;
  }
Convenience wrapper for llap tokens, that decodes max lifetime only once on adding and maintains expiration time.
llap-server/src/java/org/apache/hadoop/hive/llap/daemon/impl/DefaultLlapTokenManager.java