From 69669d6cf76d25daa529324bd5bd0db81c8b4cd3 Mon Sep 17 00:00:00 2001 From: Pascal Davoust Date: Mon, 15 Mar 2021 11:56:41 +0100 Subject: [PATCH 1/2] Fix: remove contention during localized text lookup (JDK 1.7+) --- .../xwork2/util/AbstractLocalizedTextProvider.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/com/opensymphony/xwork2/util/AbstractLocalizedTextProvider.java b/core/src/main/java/com/opensymphony/xwork2/util/AbstractLocalizedTextProvider.java index 5c68de47bc..fd893def51 100644 --- a/core/src/main/java/com/opensymphony/xwork2/util/AbstractLocalizedTextProvider.java +++ b/core/src/main/java/com/opensymphony/xwork2/util/AbstractLocalizedTextProvider.java @@ -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; @@ -61,7 +59,7 @@ abstract class AbstractLocalizedTextProvider implements LocalizedTextProvider { private final ConcurrentMap messageFormats = new ConcurrentHashMap<>(); private final ConcurrentMap> classLoaderMap = new ConcurrentHashMap<>(); - private final Set missingBundles = Collections.synchronizedSet(new HashSet()); + private final ConcurrentMap missingBundles = new ConcurrentHashMap<>(); private final ConcurrentMap delegatedClassLoaderMap = new ConcurrentHashMap<>(); /** @@ -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; } @@ -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.put(key, Boolean.TRUE); } } else { LOG.debug("Missing resource bundle [{}]!", aBundleName); - missingBundles.add(key); + missingBundles.put(key, Boolean.TRUE); } } return bundle; From 280f25d2feca8c6012960e1ebe9c78ba0459c11a Mon Sep 17 00:00:00 2001 From: Pascal Davoust Date: Mon, 22 Mar 2021 08:50:59 +0100 Subject: [PATCH 2/2] Update AbstractLocalizedTextProvider.java Applied code review comments from JCgH4164838Gh792C124B5 into account --- .../xwork2/util/AbstractLocalizedTextProvider.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/com/opensymphony/xwork2/util/AbstractLocalizedTextProvider.java b/core/src/main/java/com/opensymphony/xwork2/util/AbstractLocalizedTextProvider.java index fd893def51..05d86dcd1e 100644 --- a/core/src/main/java/com/opensymphony/xwork2/util/AbstractLocalizedTextProvider.java +++ b/core/src/main/java/com/opensymphony/xwork2/util/AbstractLocalizedTextProvider.java @@ -59,7 +59,7 @@ abstract class AbstractLocalizedTextProvider implements LocalizedTextProvider { private final ConcurrentMap messageFormats = new ConcurrentHashMap<>(); private final ConcurrentMap> classLoaderMap = new ConcurrentHashMap<>(); - private final ConcurrentMap missingBundles = new ConcurrentHashMap<>(); + private final ConcurrentMap missingBundles = new ConcurrentHashMap<>(); private final ConcurrentMap delegatedClassLoaderMap = new ConcurrentHashMap<>(); /** @@ -411,11 +411,11 @@ public ResourceBundle findResourceBundle(String aBundleName, Locale locale) { } } catch (MissingResourceException e) { LOG.debug("Missing resource bundle [{}]!", aBundleName, e); - missingBundles.put(key, Boolean.TRUE); + missingBundles.putIfAbsent(key, Boolean.TRUE); } } else { LOG.debug("Missing resource bundle [{}]!", aBundleName); - missingBundles.put(key, Boolean.TRUE); + missingBundles.putIfAbsent(key, Boolean.TRUE); } } return bundle;