HADOOP-10829. Iteration on CredentialProviderFactory.serviceLoader is thread-unsafe. Contributed by Benoy Antony and Rakesh R.

This commit is contained in:
Jitendra Pandey 2017-07-07 12:45:37 -07:00
parent d94b30cb03
commit b82485d6fe
1 changed files with 10 additions and 0 deletions

View File

@ -22,6 +22,7 @@ import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.ServiceLoader; import java.util.ServiceLoader;
@ -49,6 +50,15 @@ public abstract class CredentialProviderFactory {
ServiceLoader.load(CredentialProviderFactory.class, ServiceLoader.load(CredentialProviderFactory.class,
CredentialProviderFactory.class.getClassLoader()); CredentialProviderFactory.class.getClassLoader());
// Iterate through the serviceLoader to avoid lazy loading.
// Lazy loading would require synchronization in concurrent use cases.
static {
Iterator<CredentialProviderFactory> iterServices = serviceLoader.iterator();
while (iterServices.hasNext()) {
iterServices.next();
}
}
public static List<CredentialProvider> getProviders(Configuration conf public static List<CredentialProvider> getProviders(Configuration conf
) throws IOException { ) throws IOException {
List<CredentialProvider> result = new ArrayList<CredentialProvider>(); List<CredentialProvider> result = new ArrayList<CredentialProvider>();