]> granicus.if.org Git - icu/commitdiff
ICU-9309 multithreaded startup fix
authorAndy Heninger <andy.heninger@gmail.com>
Tue, 8 May 2012 23:05:14 +0000 (23:05 +0000)
committerAndy Heninger <andy.heninger@gmail.com>
Tue, 8 May 2012 23:05:14 +0000 (23:05 +0000)
X-SVN-Rev: 31804

icu4j/main/classes/core/src/com/ibm/icu/impl/ICUResourceBundle.java

index 4440faeb4c320bb99b5937f7ef4843b82923d8bc..748ec3966ba26d00bc05523a5706e2fc0b82c38b 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * *****************************************************************************
- * Copyright (C) 2005-2011, International Business Machines Corporation and    *
+ * Copyright (C) 2005-2012, International Business Machines Corporation and    *
  * others. All Rights Reserved.                                                *
  * *****************************************************************************
  */
@@ -726,10 +726,22 @@ public  class ICUResourceBundle extends UResourceBundle {
             return nameSet;
         }
         Set<String> getFullLocaleNameSet() {
-            if (fullNameSet == null) {
-              fullNameSet = createFullLocaleNameSet(prefix, loader);
+            // When there's no prebuilt index, we iterate through the jar files
+            // and read the contents to build it.  If many threads try to read the
+            // same jar at the same time, java thrashes.  Synchronize here
+            // so that we can avoid this problem. We don't synchronize on the
+            // other methods since they don't do this.
+            //
+            // This is the common entry point for access into the code that walks
+            // through the resources, and is cached.  So it's a good place to lock
+            // access.  Locking in the URLHandler doesn't give us a common object
+            // to lock.
+            synchronized(this) {
+                if (fullNameSet == null) {
+                    fullNameSet = createFullLocaleNameSet(prefix, loader);
+                }
+                return fullNameSet;
             }
-            return fullNameSet;
         }
     }