private static void renewCCTokenAsync(final Jwt jwt) {
        // Not expired yet, try to renew async but let requests use the old token.
        logger.trace("In renew window but token is not expired yet.");
        if(!jwt.isRenewing() || System.currentTimeMillis() > jwt.getEarlyRetryTimeout()) {
            jwt.setRenewing(true);
            jwt.setEarlyRetryTimeout(System.currentTimeMillis() + jwt.getEarlyRefreshRetryDelay());
            logger.trace("Retrieve token async is called while token is not expired yet");

            ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();

            executor.schedule(() -> {
                Result<Jwt> result = getCCTokenRemotely(jwt);
                if(result.isFailure()) {
                    // swallow the exception here as it is on a best effort basis.
                    logger.error("Async retrieve token error with status: {}", result.getError().toString());
                }
                //set renewing flag to false after response, doesn't matter if it's success or fail.
                jwt.setRenewing(false);
            }, 50, TimeUnit.MILLISECONDS);
            executor.shutdown();
        }
    }
private static void renewCCTokenAsync ( final Jwt jwt ) { logger . trace ( "In renew window but token is not expired yet." ) ; if ( ! jwt . isRenewing ( ) || System . currentTimeMillis ( ) > jwt . getEarlyRetryTimeout ( ) ) { jwt . setRenewing ( true ) ; jwt . setEarlyRetryTimeout ( System . currentTimeMillis ( ) + jwt . getEarlyRefreshRetryDelay ( ) ) ; logger . trace ( "Retrieve token async is called while token is not expired yet" ) ; ScheduledExecutorService executor = Executors . newSingleThreadScheduledExecutor ( ) ; executor . schedule ( ( ) -> { Result < Jwt > result = getCCTokenRemotely ( jwt ) ; if ( result . isFailure ( ) ) { logger . error ( "Async retrieve token error with status: {}" , result . getError ( ) . toString ( ) ) ; } jwt . setRenewing ( false ) ; } , 50 , TimeUnit . MILLISECONDS ) ; executor . shutdown ( ) ; } }
renew the given Jwt jwt asynchronously.
When fail, it will swallow the exception, so no need return type to be handled by caller.
@param jwt the jwt you want to renew