HADOOP-10829. Iteration on CredentialProviderFactory.serviceLoader is thread-unsafe. Contributed by Benoy Antony and Rakesh R.
This commit is contained in:
parent
5496a34c0c
commit
f1efa14fc6
@ -22,6 +22,7 @@
|
|||||||
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 CredentialProvider createProvider(URI providerName,
|
|||||||
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>();
|
||||||
|
Loading…
Reference in New Issue
Block a user