@Override
    public AWSCredentials getCredentials() {
        if (reuseLastProvider && lastUsedProvider != null) {
            return lastUsedProvider.getCredentials();
        }

        List<String> exceptionMessages = null;
        for (AWSCredentialsProvider provider : credentialsProviders) {
            try {
                AWSCredentials credentials = provider.getCredentials();

                if (credentials.getAWSAccessKeyId() != null &&
                    credentials.getAWSSecretKey() != null) {
                    log.debug("Loading credentials from " + provider.toString());

                    lastUsedProvider = provider;
                    return credentials;
                }
            } catch (Exception e) {
                // Ignore any exceptions and move onto the next provider
                String message;
                if (log.isDebugEnabled()) {
                    message = provider + ": " + ExceptionUtils.exceptionStackTrace(e);
                    log.debug("Unable to load credentials from " + message);
                } else {
                    message = provider + ": " + e.getMessage();
                }
                if (exceptionMessages == null) {
                    exceptionMessages = new LinkedList<String>();
                }
                exceptionMessages.add(message);
            }
        }
        throw new SdkClientException("Unable to load AWS credentials from any provider in the chain: "
                                     + exceptionMessages);
    }
Enables or disables caching of the last successful credentials provider
in this chain. Reusing the last successful credentials provider will
typically return credentials faster than searching through the chain.

@param b
           Whether to enable or disable reusing the last successful
           credentials provider for future credentials requests instead
           of searching through the whole chain.
aws-java-sdk-core/src/main/java/com/amazonaws/auth/AWSCredentialsProviderChain.java