* Custom serialization: save property bag and symbols; the formatter object can be re-created
* from just that amount of information.
*/
- private void writeObject(ObjectOutputStream oos) throws IOException {
+ private synchronized void writeObject(ObjectOutputStream oos) throws IOException {
// ICU 59 custom serialization.
// Write class metadata and serialVersionOnStream field:
oos.defaultWriteObject();
return result;
}
- private static final ThreadLocal<Properties> threadLocalCurrencyProperties =
- new ThreadLocal<Properties>() {
- @Override
- protected Properties initialValue() {
- return new Properties();
- }
- };
-
/**
* {@inheritDoc}
*
public StringBuffer format(CurrencyAmount currAmt, StringBuffer toAppendTo, FieldPosition pos) {
// TODO: This is ugly (although not as ugly as it was in ICU 58).
// Currency should be a free parameter, not in property bag. Fix in ICU 60.
- Properties cprops = threadLocalCurrencyProperties.get();
+ Properties cprops = threadLocalProperties.get();
SingularFormat fmt = null;
synchronized (this) {
// Use the pre-compiled formatter if possible. Otherwise, copy the properties
*/
@Override
public Number parse(String text, ParsePosition parsePosition) {
+ Properties pprops = threadLocalProperties.get();
+ synchronized (this) {
+ pprops.copyFrom(properties);
+ }
// Backwards compatibility: use currency parse mode if this is a currency instance
- Number result = Parse.parse(text, parsePosition, properties, symbols);
+ Number result = Parse.parse(text, parsePosition, pprops, symbols);
// Backwards compatibility: return com.ibm.icu.math.BigDecimal
if (result instanceof java.math.BigDecimal) {
result = new com.ibm.icu.math.BigDecimal((java.math.BigDecimal) result);
* @category Currency
* @stable ICU 4.2
*/
- public CurrencyPluralInfo getCurrencyPluralInfo() {
+ public synchronized CurrencyPluralInfo getCurrencyPluralInfo() {
// CurrencyPluralInfo also is not exported.
return properties.getCurrencyPluralInfo();
}
* @category Currency
* @stable ICU 4.2
*/
- public void setCurrencyPluralInfo(CurrencyPluralInfo newInfo) {
+ public synchronized void setCurrencyPluralInfo(CurrencyPluralInfo newInfo) {
properties.setCurrencyPluralInfo(newInfo);
refreshFormatter();
}
return properties.hashCode();
}
- private static final ThreadLocal<Properties> threadLocalToPatternProperties =
- new ThreadLocal<Properties>() {
- @Override
- protected Properties initialValue() {
- return new Properties();
- }
- };
-
/**
* Returns the default value of toString() with extra DecimalFormat-specific information appended
* to the end of the string. This extra information is intended for debugging purposes, and the
// to keep affix patterns intact. In particular, pull rounding properties
// so that CurrencyUsage is reflected properly.
// TODO: Consider putting this logic in PatternString.java instead.
- Properties tprops = threadLocalToPatternProperties.get();
- tprops.copyFrom(properties);
+ Properties tprops = threadLocalProperties.get().copyFrom(properties);
if (com.ibm.icu.impl.number.formatters.CurrencyFormat.useCurrency(properties)) {
tprops.setMinimumFractionDigits(exportedProperties.getMinimumFractionDigits());
tprops.setMaximumFractionDigits(exportedProperties.getMaximumFractionDigits());
return fq;
}
+ private static final ThreadLocal<Properties> threadLocalProperties =
+ new ThreadLocal<Properties>() {
+ @Override
+ protected Properties initialValue() {
+ return new Properties();
+ }
+ };
+
/** Rebuilds the formatter object from the property bag. */
void refreshFormatter() {
if (exportedProperties == null) {