*/
private ULocale _locale;
private TimeZoneNames _tznames;
- private TimeZoneGenericNames _gnames;
+ private volatile TimeZoneGenericNames _gnames;
private String _gmtPattern;
private String[] _gmtOffsetPatterns;
private String[] _gmtOffsetDigits;
protected TimeZoneFormat(ULocale locale) {
_locale = locale;
_tznames = TimeZoneNames.getInstance(locale);
- _gnames = TimeZoneGenericNames.getInstance(locale);
+ // TimeZoneGenericNames _gnames will be instantiated lazily
String gmtPattern = null;
String hourFormats = null;
return _tznames;
}
+ /**
+ * Private method returning the instance of TimeZoneGenericNames
+ * used by this object. The instance of TimeZoneGenericNames might
+ * not be available until the first use (lazy instantiation) because
+ * it is only required for handling generic names (that are not used
+ * by DateFormat's default patterns) and it requires relatively heavy
+ * one time initialization.
+ * @return the instance of TimeZoneGenericNames used by this object.
+ */
+ private TimeZoneGenericNames getTimeZoneGenericNames() {
+ if (_gnames == null) { // _gnames is volatile
+ synchronized(this) {
+ if (_gnames == null) {
+ _gnames = TimeZoneGenericNames.getInstance(_locale);
+ }
+ }
+ }
+ return _gnames;
+ }
+
/**
* Sets the time zone display name data to this instance.
*
switch (style) {
case GENERIC_LOCATION:
- result = _gnames.getGenericLocationName(ZoneMeta.getCanonicalCLDRID(tz));
+ result = getTimeZoneGenericNames().getGenericLocationName(ZoneMeta.getCanonicalCLDRID(tz));
break;
case GENERIC_LONG:
- result = _gnames.getDisplayName(tz, GenericNameType.LONG, date);
+ result = getTimeZoneGenericNames().getDisplayName(tz, GenericNameType.LONG, date);
break;
case GENERIC_SHORT:
- result = _gnames.getDisplayName(tz, GenericNameType.SHORT, date);
+ result = getTimeZoneGenericNames().getDisplayName(tz, GenericNameType.SHORT, date);
break;
case SPECIFIC_LONG:
result = formatSpecific(tz, NameType.LONG_STANDARD, NameType.LONG_DAYLIGHT, date, timeType);
genericNameTypes = EnumSet.of(GenericNameType.SHORT, GenericNameType.LOCATION);
break;
}
- GenericMatchInfo bestGeneric = _gnames.findBestMatch(text, startIdx, genericNameTypes);
+ GenericMatchInfo bestGeneric = getTimeZoneGenericNames().findBestMatch(text, startIdx, genericNameTypes);
if (bestGeneric != null) {
if (timeType != null) {
timeType.value = bestGeneric.timeType();
}
// Then generic names
- GenericMatchInfo bestGeneric = _gnames.findBestMatch(text, startIdx, ALL_GENERIC_NAME_TYPES);
+ GenericMatchInfo bestGeneric = getTimeZoneGenericNames().findBestMatch(text, startIdx, ALL_GENERIC_NAME_TYPES);
if (bestSpecific != null || bestGeneric != null) {
if (bestGeneric == null ||