Better concurrency with the Java 8 API ConcurrentMap#computeIfAbsent().
This commit is contained in:
parent
89bcc5f80e
commit
5648bc42e2
|
@ -653,16 +653,9 @@ public class FastDateParser implements DateParser, Serializable {
|
||||||
*/
|
*/
|
||||||
private Strategy getLocaleSpecificStrategy(final int field, final Calendar definingCalendar) {
|
private Strategy getLocaleSpecificStrategy(final int field, final Calendar definingCalendar) {
|
||||||
final ConcurrentMap<Locale, Strategy> cache = getCache(field);
|
final ConcurrentMap<Locale, Strategy> cache = getCache(field);
|
||||||
Strategy strategy = cache.get(locale);
|
return cache.computeIfAbsent(locale, k -> {
|
||||||
if (strategy == null) {
|
return field == Calendar.ZONE_OFFSET ? new TimeZoneStrategy(locale) : new CaseInsensitiveTextStrategy(field, definingCalendar, locale);
|
||||||
strategy = field == Calendar.ZONE_OFFSET ? new TimeZoneStrategy(locale)
|
});
|
||||||
: new CaseInsensitiveTextStrategy(field, definingCalendar, locale);
|
|
||||||
final Strategy inCache = cache.putIfAbsent(locale, strategy);
|
|
||||||
if (inCache != null) {
|
|
||||||
return inCache;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return strategy;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue