ICU-7107 Fixed TimeZone#getDisplayName threading problem.

X-SVN-Rev: 26591
This commit is contained in:
Yoshito Umaoka 2009-09-03 18:57:40 +00:00
parent 42d4b38e15
commit ddd8a50457
2 changed files with 32 additions and 3 deletions

View File

@ -446,7 +446,7 @@ abstract public class TimeZone implements Serializable, Cloneable {
* SHORT, LONG, SHORT_GENERIC, LONG_GENERIC, SHORT_GMT, LONG_GMT,
* SHORT_COMMONLY_USED and GENERIC_LOCATION.
*/
private synchronized String _getDisplayName(boolean daylight, int style, ULocale locale) {
private String _getDisplayName(boolean daylight, int style, ULocale locale) {
if (locale == null) {
throw new NullPointerException("locale is null");
}
@ -464,10 +464,13 @@ abstract public class TimeZone implements Serializable, Cloneable {
// We keep a cache, indexed by locale. The cache contains a
// SimpleDateFormat object, which we create on demand.
SimpleDateFormat format = cachedLocaleData.get(locale);
if (format == null) {
SimpleDateFormat format;
SimpleDateFormat tmpfmt = cachedLocaleData.get(locale);
if (tmpfmt == null) {
format = new SimpleDateFormat(null, locale);
cachedLocaleData.put(locale, format);
} else {
format = (SimpleDateFormat)tmpfmt.clone();
}
String[] patterns = { "z", "zzzz", "v", "vvvv", "Z", "ZZZZ", "V", "VVVV" };

View File

@ -1149,7 +1149,33 @@ public class TimeZoneRegression extends TestFmwk {
} else {
logln("OK: zone " + j_id +" returned offset in December: " + offset2);
}
}
public void TestT7107() {
Thread[] workers = new Thread[20];
for (int i = 0 ; i < workers.length; i++) {
workers[i] = new Thread(new Runnable() {
public void run() {
for (int j = 0; j < 10000; j++) {
try {
com.ibm.icu.util.TimeZone.getTimeZone("GMT").getDisplayName();
} catch (Exception e) {
errln("FAIL: Caught an exception " + e);
}
}
}
});
}
for (Thread wk : workers) {
wk.start();
}
for (Thread wk : workers) {
try {
wk.join();
} catch (InterruptedException ie) {
}
}
}
}