Skip to content

Commit

Permalink
Merge pull request #477 from davoustp/contention-in-localized-resourc…
Browse files Browse the repository at this point in the history
…es-2.5.x

[WW-5119] Fix: remove contention during localized text lookup (JDK 1.7+)
  • Loading branch information
lukaszlenart committed Mar 22, 2021
2 parents 39d70e3 + 280f25d commit 1b9563d
Showing 1 changed file with 4 additions and 6 deletions.
Expand Up @@ -31,8 +31,6 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.MessageFormat;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -61,7 +59,7 @@ abstract class AbstractLocalizedTextProvider implements LocalizedTextProvider {

private final ConcurrentMap<MessageFormatKey, MessageFormat> messageFormats = new ConcurrentHashMap<>();
private final ConcurrentMap<Integer, List<String>> classLoaderMap = new ConcurrentHashMap<>();
private final Set<String> missingBundles = Collections.synchronizedSet(new HashSet<String>());
private final ConcurrentMap<String, Boolean> missingBundles = new ConcurrentHashMap<>();
private final ConcurrentMap<Integer, ClassLoader> delegatedClassLoaderMap = new ConcurrentHashMap<>();

/**
Expand Down Expand Up @@ -390,7 +388,7 @@ public ResourceBundle findResourceBundle(String aBundleName, Locale locale) {
ClassLoader classLoader = getCurrentThreadContextClassLoader();
String key = createMissesKey(String.valueOf(classLoader.hashCode()), aBundleName, locale);

if (missingBundles.contains(key)) {
if (missingBundles.containsKey(key)) {
return null;
}

Expand All @@ -413,11 +411,11 @@ public ResourceBundle findResourceBundle(String aBundleName, Locale locale) {
}
} catch (MissingResourceException e) {
LOG.debug("Missing resource bundle [{}]!", aBundleName, e);
missingBundles.add(key);
missingBundles.putIfAbsent(key, Boolean.TRUE);
}
} else {
LOG.debug("Missing resource bundle [{}]!", aBundleName);
missingBundles.add(key);
missingBundles.putIfAbsent(key, Boolean.TRUE);
}
}
return bundle;
Expand Down

0 comments on commit 1b9563d

Please sign in to comment.