diff --git a/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ConversionUtils.java b/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ConversionUtils.java index 441bb0b0e..23234a4d6 100644 --- a/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ConversionUtils.java +++ b/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ConversionUtils.java @@ -39,8 +39,6 @@ import java.util.Locale; import java.util.Map; import java.util.TimeZone; -import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.ConcurrentHashMap; import org.apache.commons.lang3.ArrayUtils; import org.slf4j.LoggerFactory; @@ -66,7 +64,7 @@ public class ConversionUtils private static final int STYLE_INTEGER = 4; // cache custom formats - private static ConcurrentMap customFormatsCache = new ConcurrentHashMap(); + private static final ThreadLocal> CUSTOM_FORMATS_CACHE = ThreadLocal.withInitial(HashMap::new); private ConversionUtils() {} @@ -102,11 +100,11 @@ public static NumberFormat getNumberFormat(String format, Locale locale) { // we have a custom format String cacheKey = format + "%" + locale.toString(); - nf = customFormatsCache.get(cacheKey); + nf = CUSTOM_FORMATS_CACHE.get().get(cacheKey); if( nf == null ) { nf = new DecimalFormat(format, new DecimalFormatSymbols(locale)); - customFormatsCache.put(cacheKey,nf); + CUSTOM_FORMATS_CACHE.get().put(cacheKey,nf); } } else