diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/alias/CredentialProviderFactory.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/alias/CredentialProviderFactory.java index d1e3eb5437..1b2ac41fa8 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/alias/CredentialProviderFactory.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/alias/CredentialProviderFactory.java @@ -22,6 +22,7 @@ import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import java.util.ServiceLoader; @@ -49,6 +50,15 @@ public abstract CredentialProvider createProvider(URI providerName, ServiceLoader.load(CredentialProviderFactory.class, CredentialProviderFactory.class.getClassLoader()); + // Iterate through the serviceLoader to avoid lazy loading. + // Lazy loading would require synchronization in concurrent use cases. + static { + Iterator iterServices = serviceLoader.iterator(); + while (iterServices.hasNext()) { + iterServices.next(); + } + } + public static List getProviders(Configuration conf ) throws IOException { List result = new ArrayList();