/*
*******************************************************************************
- * Copyright (C) 2014, International Business Machines Corporation and
+ * Copyright (C) 2014-2015, International Business Machines Corporation and
* others. All Rights Reserved.
*******************************************************************************
*/
synchronized(TZDBTimeZoneNames.class) {
if (TZDB_NAMES_TRIE == null) {
// loading all names into trie
- TZDB_NAMES_TRIE = new TextTrieMap<TZDBNameInfo>(true);
+ TextTrieMap<TZDBNameInfo> trie = new TextTrieMap<TZDBNameInfo>(true);
Set<String> mzIDs = TimeZoneNamesImpl._getAvailableMetaZoneIDs();
for (String mzID : mzIDs) {
TZDBNames names = getMetaZoneNames(mzID);
stdInf.type = NameType.SHORT_STANDARD;
stdInf.ambiguousType = ambiguousType;
stdInf.parseRegions = parseRegions;
- TZDB_NAMES_TRIE.put(std, stdInf);
+ trie.put(std, stdInf);
}
if (dst != null) {
TZDBNameInfo dstInf = new TZDBNameInfo();
dstInf.type = NameType.SHORT_DAYLIGHT;
dstInf.ambiguousType = ambiguousType;
dstInf.parseRegions = parseRegions;
- TZDB_NAMES_TRIE.put(dst, dstInf);
+ trie.put(dst, dstInf);
}
}
+ TZDB_NAMES_TRIE = trie;
}
}
}
/*
********************************************************************************
- * Copyright (C) 2007-2014, Google, International Business Machines Corporation *
+ * Copyright (C) 2007-2015, Google, International Business Machines Corporation *
* and others. All Rights Reserved. *
********************************************************************************
*/
import java.text.ParseException;
import java.text.ParsePosition;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.EnumSet;
import java.util.Locale;
import java.util.Set;
import java.util.TreeSet;
+import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Pattern;
+import com.ibm.icu.impl.TZDBTimeZoneNames;
import com.ibm.icu.impl.ZoneMeta;
import com.ibm.icu.lang.UCharacter;
import com.ibm.icu.text.SimpleDateFormat;
import com.ibm.icu.text.TimeZoneFormat.Style;
import com.ibm.icu.text.TimeZoneFormat.TimeType;
import com.ibm.icu.text.TimeZoneNames;
+import com.ibm.icu.text.TimeZoneNames.NameType;
import com.ibm.icu.util.BasicTimeZone;
import com.ibm.icu.util.Calendar;
import com.ibm.icu.util.Output;
}
}
}
+
+ // This is a test case of Ticket#11487.
+ // Because the problem is reproduced for the very first time,
+ // the reported problem cannot be reproduced with regular test
+ // execution. Run this test alone reproduced the problem before
+ // the fix was merged.
+ public void TestTZDBNamesThreading() {
+ final TZDBTimeZoneNames names = new TZDBTimeZoneNames(ULocale.ENGLISH);
+ final AtomicInteger found = new AtomicInteger();
+ List<Thread> threads = new ArrayList<Thread>();
+ final int numIteration = 1000;
+
+ try {
+ for (int i = 0; i < numIteration; i++) {
+ Thread thread = new Thread() {
+ @Override
+ public void run() {
+ int resultSize = names.find("GMT", 0, EnumSet.allOf(NameType.class)).size();
+ if (resultSize > 0) {
+ found.incrementAndGet();
+ }
+ }
+ };
+ thread.start();
+ threads.add(thread);
+ }
+
+ for(Thread thread: threads) {
+ thread.join();
+ }
+ } catch (Throwable t) {
+ errln(t.toString());
+ }
+
+ if (found.intValue() != numIteration) {
+ errln("Incorrect count: " + found.toString() + ", expected: " + numIteration);
+ }
+ }
}
\ No newline at end of file