From: Andy Heninger Date: Tue, 8 May 2012 23:05:14 +0000 (+0000) Subject: ICU-9309 multithreaded startup fix X-Git-Tag: milestone-59-0-1~3835 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f2a5abcf832e9552ccb1abb34a5fdf261373b19f;p=icu ICU-9309 multithreaded startup fix X-SVN-Rev: 31804 --- diff --git a/icu4j/main/classes/core/src/com/ibm/icu/impl/ICUResourceBundle.java b/icu4j/main/classes/core/src/com/ibm/icu/impl/ICUResourceBundle.java index 4440faeb4c3..748ec3966ba 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/impl/ICUResourceBundle.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/impl/ICUResourceBundle.java @@ -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 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; } }