Commits

Anonymous committed 7477c3c

XW-704 remove synchronized block and use a CopyOnWriteArrayList. The overhead of the copy operations is justified because the list has very few modifications and is usually traversed, so copying is cheaper than synchronizing (this list is usually small, on top of that)

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@2026e221344d-f017-0410-9bd5-d282ab1896d7

  • Participants
  • Parent commits d1a093a

Comments (0)

Files changed (1)

core/src/main/java/com/opensymphony/xwork2/util/LocalizedTextUtil.java

 import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.CopyOnWriteArrayList;
 
 
 /**
  */
 public class LocalizedTextUtil {
 
-    private static final List<String> DEFAULT_RESOURCE_BUNDLES = Collections.synchronizedList(new ArrayList<String>());
+    private static final List<String> DEFAULT_RESOURCE_BUNDLES = new CopyOnWriteArrayList<String>();
     private static final Logger LOG = LoggerFactory.getLogger(LocalizedTextUtil.class);
     private static boolean reloadBundles = false;
     private static final ResourceBundle EMPTY_BUNDLE = new EmptyResourceBundle();
      * @return a localized message based on the specified key, or null if no localized message can be found for it
      */
     public static String findDefaultText(String aTextName, Locale locale) {
-        synchronized (DEFAULT_RESOURCE_BUNDLES) {
-            List<String> localList = DEFAULT_RESOURCE_BUNDLES;
-
-            for (String bundleName : localList) {
-                ResourceBundle bundle = findResourceBundle(bundleName, locale);
-                if (bundle != null) {
-                    reloadBundles();
-                    try {
-                        return bundle.getString(aTextName);
-                    } catch (MissingResourceException e) {
-                        // ignore and try others
-                    }
+        List<String> localList = DEFAULT_RESOURCE_BUNDLES;
+
+        for (String bundleName : localList) {
+            ResourceBundle bundle = findResourceBundle(bundleName, locale);
+            if (bundle != null) {
+                reloadBundles();
+                try {
+                    return bundle.getString(aTextName);
+                } catch (MissingResourceException e) {
+                    // ignore and try others
                 }
             }
         }