private boolean needsRecreate(TokenWrapper token) {
    long now = Time.now();
    long tokenWholeLifeTimeMs = token.maxDate - token.issueDate;
    long tokenRemainingLifeTimeMs = Math.max(token.maxDate - now, 0);
    // a number which tells how close if maxDate, e.g. 0.1 means only 10% of the token lifetime left
    double tokenRemainingLifeTimePercent = (double) tokenRemainingLifeTimeMs / tokenWholeLifeTimeMs;
    boolean needsRecreate = tokenRemainingLifeTimePercent < 0.1;

    LOG.debug(
        "Token needsRecreate? {}, now: {}, maxDate: {}, issueDate: {}, tokenWholeLifeTime(ms): {}, "
            + "tokenRemainingLifeTime(ms): {}, tokenRemainingLifeTimePercent: {}%",
        needsRecreate, now, token.maxDate, token.issueDate, tokenWholeLifeTimeMs, tokenRemainingLifeTimeMs,
        toPercentString(tokenRemainingLifeTimePercent));
    return needsRecreate;
  }
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